Friday, August 24, 2012

Web API in ASP.NET MVC4

In the new version of ASP.NET, Microsoft has introduced some framework extension that has exciting possibilities.  Google, FaceBook, and the like have been exposing web API in some fashion for a while now, but it has always seemed limited to certain platforms.  It appears at a glance that we will be able to provide the same functionality with native ASP.NET and MVC4 applications.  This basically allows you to expose web service over straight up HTTP instead of traditional service hosting/messaging.

The gain is that you can create web-based integration points by leveraging  a native ASP.NET architecture at the same time.  This allows you to provide a user-story-based integration routine (ala FaceBook, Twitter) as a wrapper of /or in addition to any service layer integrations that may be exposed.  

Here are some points I read from Scott Gu's Blog on the topic.  He outlines the highlights and additions to the framework.  I think the real excitement is in the realization of the walls that are coming down on platform dependence and ease of developing rich client experiences with web services in a Windows environment.

Our new ASP.NET Web API support enables you to easily create powerful Web APIs that can be accessed from a broad range of clients (ranging from browsers using JavaScript, to native apps on any mobile/client platform).  It provides the following support:
  • Modern HTTP programming model: Directly access and manipulate HTTP requests and responses in your Web APIs using a clean, strongly typed HTTP object model.  In addition to supporting this HTTP programming model on the server, we also support the same programming model on the client with the new HttpClient API that can be used to call Web APIs from any .NET application.
  • Content negotiation: Web API has built-in support for content negotiation – which enables the client and server to work together to determine the right format for data being returned from an API.  We provide default support for JSON, XML and Form URL-encoded formats, and you can extend this support by adding your own formatters, or even replace the default content negotiation strategy with one of your own.
  • Query composition: Web API enables you to easily support querying via the OData URL conventions.  When you return a type of IQueryable<T> from your Web API, the framework will automatically provide OData query support over it – making it easy to implement paging and sorting.
  • Model binding and validation: Model binders provide an easy way to extract data from various parts of an HTTP request and convert those message parts into .NET objects which can be used by Web API actions.  Web API supports the same model binding and validation infrastructure that ASP.NET MVC supports today.
  • Routes: Web APIs support the full set of routing capabilities supported within ASP.NET MVC and ASP.NET today, including route parameters and constraints. Web API also provides smart conventions by default, enabling you to easily create classes that implement Web APIs without having to apply attributes to your classes or methods.  Web API configuration is accomplished solely through code – leaving your config files clean.
  • Filters: Web APIs enables you to easily use and create filters (for example: [authorization]) that enable you to encapsulate and apply cross-cutting behavior.
  • Improved testability: Rather than setting HTTP details in static context objects, Web API actions can now work with instances of HttpRequestMessage and HttpResponseMessage – two new HTTP objects that (among other things) make testing much easier. As an example, you can unit test your Web APIs without having to use a Mocking framework.
  • IoC Support: Web API supports the service locator pattern implemented by ASP.NET MVC, which enables you to resolve dependencies for many different facilities.  You can easily integrate this with an IoC container or dependency injection framework to enable clean resolution of dependencies.
  • Flexible Hosting: Web APIs can be hosted within any type of ASP.NET application (including both ASP.NET MVC and ASP.NET Web Forms based applications).  We’ve also designed the Web API support so that you can also optionally host/expose them within your own process if you don’t want to use ASP.NET/IIS to do so.  This gives you maximum flexibility in how and where you use it.

18 comments:

  1. Well, this is pretty good information which is useful for me because I am working in an Offshore Software Development Company and writing an article about network security.

    ReplyDelete
  2. I think the admin of this website is truly working hard in support of his web page, since here every data is quality
    based data.

    Also visit my blog :: buy phen375

    ReplyDelete
  3. It's not my first time to go to see this website, i am browsing this web site dailly and take nice information from here everyday.

    Here is my site ... buy meratol uk

    ReplyDelete
  4. I'm not sure why but this web site is loading very slow for me. Is anyone else having this problem or is it a problem on my end? I'll check back later
    on and see if the problem still exists.

    Have a look at my web blog :: buy vigrx plus

    ReplyDelete
  5. Oh my goodness! Amazing article dude! Thank you so much, However
    I am having problems with your RSS. I don't understand why I can't subscribe to it.
    Is there anybody getting similar RSS problems? Anybody who knows the
    answer can you kindly respond? Thanks!!

    Feel free to visit my homepage - buy virility ex

    ReplyDelete
  6. Can you tell us more about this? I'd want to find out more details.

    My webpage :: buy xtremeno

    ReplyDelete
  7. What's up to every , for the reason that I am actually keen of reading this blog's post to be updated daily.
    It consists of nice material.

    My webpage :: is hoodia gordonii safe

    ReplyDelete
  8. Thanks for another great article. Where
    else may just anybody get that kind of information
    in such an ideal means of writing? I've a presentation next week, and I am at the look for such information.

    Here is my homepage: http://www.luxe-etc.com/en/index.php/member/98252

    ReplyDelete
  9. For hottest information you have to visit world-wide-web and
    on web I found this site as a best site for hottest updates.



    Feel free to surf to my web-site - buy thyromine

    ReplyDelete
  10. I was curious if you ever thought of changing the page
    layout of your blog? Its very well written; I love what youve got to say.
    But maybe you could a little more in the way of content so people could connect with it better.
    Youve got an awful lot of text for only having 1 or 2 pictures.

    Maybe you could space it out better?

    Look into my blog post naturally repairs skin

    ReplyDelete
  11. Wow, that's what I was looking for, what a stuff! existing here at this blog, thanks admin of this website.

    my blog post :: aciphex

    ReplyDelete
  12. It's amazing designed for me to have a site, which is good in favor of my experience. thanks admin

    Look at my weblog: breastactivesonline.postbit.com

    ReplyDelete
  13. Hi, its good post on the topic of media print, we all
    understand media is a great source of facts.


    Also visit my blog post - funpic.de

    ReplyDelete
  14. Hi there i am kavin, its my first occasion to commenting anywhere, when i
    read this piece of writing i thought i could also make comment due
    to this good article.

    My webpage tinnituscontrol.herbalcurenow.com

    ReplyDelete
  15. Hey! This is kind of off topic but I need some guidance from an established blog.

    Is it very hard to set up your own blog? I'm not very techincal but I can figure things out pretty quick. I'm thinking about setting up my own
    but I'm not sure where to begin. Do you have any tips or suggestions? Many thanks

    my page: http://buycapsiplex.beep.com

    ReplyDelete
  16. Every weekend i used to go to see this web page, as i want
    enjoyment, since this this web page conations truly pleasant funny information too.



    Feel free to visit my website: buy deer antler plus

    ReplyDelete
  17. I seldom leave a response, however i did a few searching and wound up here "Web API in ASP.NET MVC4".

    And I actually do have 2 questions for you if it's allright. Could it be simply me or does it appear like a few of these responses come across like they are written by brain dead visitors? :-P And, if you are posting on other sites, I'd like to follow anything fresh you have to post.
    Would you make a list of the complete urls of your communal sites like
    your Facebook page, twitter feed, or linkedin profile?


    My webpage: buy virility ex

    ReplyDelete