Download presentation
Presentation is loading. Please wait.
Published byReynold Stafford Modified over 9 years ago
2
Building HTTP Services with ASP.NET Web API Sayed Ibrahim Hashimi Program Manager Microsoft Corporation DEV309
4
Designed for broad reachUses HTTP as an application protocol, not a transport protocol
6
Why build Web APIs?
8
GET /en/html/dummy.php?name=MyName&married=not+single &male=yes HTTP/1.1 Host: www.explainth.at User-Agent: Mozilla/5.0 (Windows;en-GB; rv:1.8.0.11) Gecko/20070312 Firefox/1.5.0.11 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-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://www.explainth.at/en/misc/httpreq.shtml
9
demo Sayed Ibrahim Hashimi Program Manager Microsoft Corporation Contact Manager browser and mobile app
11
? ASP.NET MVC WCF Web HTTP WCF REST Starter Kit WCF Web API
12
+ ASP.NET MVC WCF Web HTTP WCF REST Starter Kit WCF Web API
13
ASP.NET Web API
17
demo Sayed Ibrahim Hashimi Program Manager Microsoft Corporation Your First Web API
20
Default Web API route routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } );
24
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 };
25
Content Negotiation HttpResponseMessage response = Request.CreateResponse (HttpStatusCode.Created, contact);
26
demo Sayed Ibrahim Hashimi Program Manager Microsoft Corporation Scaffolding an EF-based web API
28
Invoke Action Action filters Model Bind Select actionException filters Route to controllerFormatting RequestResponse Authorization filters
30
demo Sayed Ibrahim Hashimi Program Manager Microsoft Corporation OData query support
31
Http Client Handler Host Http Dispatcher Http Server Message handlers: Task SendAsync( HttpRequestMessage request, CancellationToken cancellationToken)
32
demo Sayed Ibrahim Hashimi Program Manager Microsoft Corporation URI format extensions
34
IApiExplorer IApiExplorer apiExplorer = config.Services.GetApiExplorer(); public interface IApiExplorer { Collection ApiDescriptions { get; } }
35
demo Sayed Ibrahim Hashimi Program Manager Microsoft Corporation Custom web API help page
37
demo Sayed Ibrahim Hashimi Program Manager Microsoft Corporation Flexible hosting
41
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
42
Visual Studio Home Page :: http://www.microsoft.com/visualstudio/en-us Jason Zander’s Blog :: http://blogs.msdn.com/b/jasonz/ Facebook :: http://www.facebook.com/visualstudio Twitter :: http://twitter.com/#!/visualstudio Somasegar’s Blog :: http://blogs.msdn.com/b/somasegar/
43
Connect. Share. Discuss. http://europe.msteched.com Learning Microsoft Certification & Training Resources www.microsoft.com/learning TechNet Resources for IT Professionals http://microsoft.com/technet Resources for Developers http://microsoft.com/msdn
44
Evaluations http://europe.msteched.com/sessions Submit your evals online
46
Why build Web APIs?
47
http://www.asp.net/web-api/overview/testing-and-debugging/tracing-in-aspnet-web-api
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.