1 / 21

ASP.NET Web API

ASP.NET Web API. Udaiappa Ramachandran NHDN-Nashua .NET/Cloud Computing UG Lead Email: udaiappa@gmail.com Blog: http://cloudycode.wordpress.com. Agenda. Introduction to Web API Web API Routing Web API Pipeline Dependency Injections and Resolvers Model Binding and Media Formats

minnie
Télécharger la présentation

ASP.NET Web API

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ASP.NET Web API Udaiappa Ramachandran NHDN-Nashua .NET/Cloud Computing UG Lead Email: udaiappa@gmail.com Blog: http://cloudycode.wordpress.com

  2. Agenda • Introduction to Web API • Web API Routing • Web API Pipeline • Dependency Injections and Resolvers • Model Binding and Media Formats • Self Hosting • Deploying Web API into cloud • References

  3. Introduction to Web API • Next iteration of WCF REST • Framework for developing REST Services • Released part of ASP.NET MVC • Uses HTTP protocol • Accessible from wide variety of clients • Http Methods: GET, POST, PUT, DELETE • URLs and Methods

  4. Demo: Web API Basics

  5. Web API Routing • Web API Routing very similar to MVC routing • Action determined using the HTTP method not the URI path • Uses “api” in the rout is to avoid collisons with ASP.NET MVC routing. • Adds “Controller” to the controller part of the URL • Default mapping thru global.asax • Additional URL parameters are mapped as action parameters • Explicitly specify the HTTP methods for an action by decorating the action method with HttpGet, HttpPut, HttpPost or HttpDelete attribute • Action can be defined thru AcceptVerbs as a method attributes • Route by Action Name • Override action name by using ActionName attribute • Ignore action by NoAction Attribute

  6. Demo: Web API Routing

  7. Filtering • Uses OData specific keywords Install-Package Microsoft.AspNet.WebApi.OData -Pre

  8. Demo: Web API Filtering

  9. Web API Pipeline • Both Request and Response Model have pipeline • Web API has client and server side pipelines • Both Share the common object HttpMessageHandler • HttpRequestMessage • Represents all info about http request such as URL, HTTP Methods and Headers • HttpResponseMessage • Represents all the info about the Http Response such as StatusCode, Success Flag, Original Http Request • HttpMessageHandler • Common for both Request and Response • Most common processing code can be placed here • Ideal for authentication • Two Scopes: Global and Per-Route • Custom Handlers • Inherit DelegatingHandler • Custom code to perform any kind of per request functionality

  10. Pipeline Elements

  11. Pipeline Elements

  12. Demo: Web API Pipeline Demo: Custom Handlers

  13. Dependency Resolution • Service Oriented Architecture for Decoupling the object • IoC: The concept of allowing something outside of system to control it. • Often done thru DI frameworks • Unity • Ninject • Castle Windsor • Structure Map • Spring.net • Autofac • Web API provides a hook for us to wire up the complex dependency

  14. Demo: Simple Resolver Demo: Resolve using DI Framework

  15. Data Model and MIME types • Returning JSON • Default return format • Good for mobile apps • does not require any special code • Returning XML • No code change • Set the request content type as application/xml • Mime Types: • return virtually anything that can be sent over the web • Inherit from BufferedMediaTypeFormatter • Override key methods • attach media formatter to configuration

  16. Demo: Data Model Demo: MIME Types

  17. Hosting • IIS • very common hosting solution • set up just like a web app • calls are made via URLs handled by the web server • Self Hosting • Not restricted to IIS • can host in your own process • uses the HttpSelfHostConfiguration • Useful for tightly focused services and apps

  18. Demo: Self Hosting

  19. Resource • http://cloudycode.wordpress.com • http://www.asp.net/web-api/overview • http://code.msdn.microsoft.com/ASPNET-Web-API-Self-Host-30abca12 • http://msdn.microsoft.com/en-us/library/gg309461.aspx • http://blogs.msdn.com/b/webdev/archive/2012/08/26/asp-net-web-api-and-httpclient-samples.aspx

  20. Q & A

More Related