Building HTTP Services with ASP.NET Web API Sayed Ibrahim Hashimi Program Manager Microsoft Corporation DEV309
Designed for broad reachUses HTTP as an application protocol, not a transport protocol
Why build Web APIs?
GET /en/html/dummy.php?name=MyName&married=not+single &male=yes HTTP/1.1 Host: User-Agent: Mozilla/5.0 (Windows;en-GB; rv: ) Gecko/ Firefox/ Accept: text/xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-gb,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO ,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer:
demo Sayed Ibrahim Hashimi Program Manager Microsoft Corporation Contact Manager browser and mobile app
? ASP.NET MVC WCF Web HTTP WCF REST Starter Kit WCF Web API
+ ASP.NET MVC WCF Web HTTP WCF REST Starter Kit WCF Web API
ASP.NET Web API
demo Sayed Ibrahim Hashimi Program Manager Microsoft Corporation Your First Web API
Default Web API route routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } );
Content Negotiation // Get the IContentNegotiator IContentNegotiator negotiator = Configuration.Services.GetContentNegotiator(); // Run content negotiation to select a formatter MediaTypeHeaderValue mediaType; MediaTypeFormatter formatter = negotiator.Negotiate( typeof(Contact), Request, Configuration.Formatters, out mediaType); // Create a response message with an object content using the selected formatter HttpResponseMessage response = new HttpResponseMessage() { Content = new ObjectContent (contact, formatter), RequestMessage = Request };
Content Negotiation HttpResponseMessage response = Request.CreateResponse (HttpStatusCode.Created, contact);
demo Sayed Ibrahim Hashimi Program Manager Microsoft Corporation Scaffolding an EF-based web API
Invoke Action Action filters Model Bind Select actionException filters Route to controllerFormatting RequestResponse Authorization filters
demo Sayed Ibrahim Hashimi Program Manager Microsoft Corporation OData query support
Http Client Handler Host Http Dispatcher Http Server Message handlers: Task SendAsync( HttpRequestMessage request, CancellationToken cancellationToken)
demo Sayed Ibrahim Hashimi Program Manager Microsoft Corporation URI format extensions
IApiExplorer IApiExplorer apiExplorer = config.Services.GetApiExplorer(); public interface IApiExplorer { Collection ApiDescriptions { get; } }
demo Sayed Ibrahim Hashimi Program Manager Microsoft Corporation Custom web API help page
demo Sayed Ibrahim Hashimi Program Manager Microsoft Corporation Flexible hosting
DEV301 ASP.NET Roadmap: One ASP.NET – Web Forms, MVC, Web API, and more DEV302 What's New in Visual Studio 2012 for Web Developers DEV303 ASP.NET Loves HTML5 DEV304 ASP.NET for Mobile and Tablet Development DEV305 Microsoft ASP.NET and the Realtime Web
Visual Studio Home Page :: Jason Zander’s Blog :: Facebook :: Twitter :: Somasegar’s Blog ::
Connect. Share. Discuss. Learning Microsoft Certification & Training Resources TechNet Resources for IT Professionals Resources for Developers
Evaluations Submit your evals online
Why build Web APIs?