dotNet Miami - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API


Published on

dotNet Miami - April 19th, 2012: Presented by Cecil Phillip:: Interested in learning about building HTTP services? Want to know how you can easily leverage HTTP in your .NET projects? Come see how the ASP.NET Web API allows you to work with HTTP in interesting ways to create rich services that are easily accessible from various clients. Along the way, we’ll also address some topics such as Content Negotiation, Validation, Media Types, Action Filters and more.

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Text based.Get requests include an initial line with the Method name, resource, and HTTP version
  • Each field may contain multiple values separated by semicolons
  • dotNet Miami - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

    1. 1. Building HTTP based Web Services with ASP.NET Web API Cecil L. Phillip @cecilphillip
    2. 2. Overview Short Review of HTTP ASP.NET Web Stack Web API Pipeline Web API Extensibility Points HTTP Tools DEMOS!!
    3. 3. Why HTTP Services ? Light Weight Support for Multiple Formats HTTP Caching Accessible from a variety devices
    4. 4. HTTP Messages Request and Response Messages consist of  An Initial Start Line  Zero or More Message Headers  An Optional Message Body RFC 2616 - HTTP 1.1 Spec 
    5. 5. HTTP Request Methods Identifies the Action against the Resource The HTTP Spec defines eight Method Types A few of these Methods include:  POST – Create a new Resource  GET – Retrieve the Resource  PUT – Create or Update a Resource  DELETE – Delete the Resource Most Web Browsers only support GET and POST
    6. 6. HTTP Headers Provide valuable meta data for the message Some Standard Headers include:  Accept – Accepted formats by the Client  Content-Type – Format associated with the request body  Host – Server domain name  User-Agent – Client software identifier Additional fields may be added by the Server or Application
    7. 7. HTTP Headers cont.. Common Uses Include  Setting Cookies  Defining Caching  Passing Authentication credentials Non standard header fields are prefixed with “X-” IANA Header Field Name Registry 
    8. 8. HTTP Status Codes Identify the type of request success and failures Some codes you might see:  2xx – Successful Response  201 - Created  3xx – Redirect Response  301 – Moved Permanently  4xx – Client Error Response  401 – Unauthorized  5xx – Service Error Response  503 – Service Unavailable
    9. 9. Web API Lineage WCF 3.5 Web HTTP WCF REST Starter Kit WCF Web API ASP.NET Web API
    10. 10. ASP.NET STACK Singe Web Web WebMVC Page SignalR Forms Pages API Apps Sites Services ASP.NET Core
    11. 11. Web API and MVC Build Web Applications with MVC and Web Services with Web API ASP.NET Web API is not dependent on ASP.NET MVC Shared Concepts between the Frameworks  Controllers  Filters  Model Binding  Model Validation  Routing  Dependency Resolver
    12. 12. Web API Framework Features Strongly Typed API for working with HTTP Messages Content Negotiation Pluggable Messaging Pipeline Code Based Configuration IoC Support OData Query Composition Flexible Hosting Options
    13. 13. Where Do I Get It? NuGet Web Platform Installer Microsoft Download Center
    14. 14. Web API PipelineAPI Client Side Message Message Http ClientHttp Client Handler Handler HandlerAPI Server Side Message Message HttpHttp Server Handler Handler Dispatcher
    15. 15. Web API Dispatcher Invoke Action Action Filters Model Binding Authorization Filters Action Selection Exception Filters Controller Selection Formatting Request Response
    16. 16. Media Types Used to Identify Resources Format Types Used in Various Networking Protocols e.g. HTTP, RTP, SMTP Vendor Specific Formats begin with vnd. Web API supports XML, JSON, and Form-Urlencoded data out of the box IANA Media Type Listing
    17. 17. Content Negotiation Service Clients tell the Server about Desired Formats Servers returns Resources in Supported Format ASP.NET Web API supports XML and JSON out of the box Additional Formats can easily plugged in
    18. 18. Filters Borrowed concept from ASP.NET MVC  Replaced Operation Handlers from the Web API Previews Can be applied on various levels  Per Controller, Per Action, or Global Filter Types  Action Filters – executes before and/or after an operation  Authorization Filters – executes before model binding  Exception Filters – catch unhandled operation exceptions
    19. 19. Message Handlers Provides a Pipeline for processing HTTP Messages Allows for Inspection and Manipulation of HTTP Messages in transit Common Uses:  Logging / Tracing  Adding and Removing HTTP Headers  Message Filtering
    20. 20. Securing Your Service Enable HTTPS / SSL on the Servers Generate API Keys Implement Authentication Tokens Use Key Encryption
    21. 21. Hosting Options ASP.NET Web Hosting Uses the HttpControllerHandler async handler Self Hosting Translates messages using a WCF channel stack In-Memory Hosting Good for testing
    22. 22. HttpClient Configurable class for sending HttpRequestMessages Originally in the Rest Starter Kit [2009] Only Asynchronous Public Methods Included in .NET 4.5 Available in the System.Net.Http NuGet Package
    23. 23. HTTP Development Tools Curl Fiddler Web Debugger Wireshark Desktop Web Browser
    24. 24. Alternatives Nancy ServiceStack OpenRasta WCF Web HTTP
    25. 25. Resources ASP.NET Web API Homepage Getting Started With ASP.NET Web API ASP.NET CodePlex Repository Twitter #aspnetwebapi
    26. 26. THANK YOU