Wcf rest api introduction

download Wcf rest api introduction

If you can't read please download the document

  • date post

    01-Nov-2014
  • Category

    Technology

  • view

    1.810
  • download

    4

Embed Size (px)

description

Presentation at DDDMelbourne.

Transcript of Wcf rest api introduction

  • 1. Doing REST with new WCF Web API
    Himanshu Desai
    Senior Consultant - Readify
    Discover. Master. Influence.
  • 2. Agenda
    Web as Resource Oriented Architecture
    • Current Industry Trends
    Overview of REST
    What is REST?
    REST Constraints
    REST Benefits
    REST using WCF
    REST Support in WCF
    WCF Web API
    Discover. Master. Influence.
  • 3. Resource Oriented Architecture
    3
    Discover. Master. Influence.
  • 4. Current Industry Trends
    A Move to cloud-based computing
    A Migration away from SOAP
    More browser based Apps
    Adoption of REST
    Other standards like OAuth, WebSockets
    Discover. Master. Influence.
    4
  • 5. What is REST?
    Representational State Transfer
    Idea floated by Roy Fielding
    Architecture Style (not a protocol or spec and it is not restricted to HTTP)
    Discover. Master. Influence.
    5
  • 6. REST Constraints
    Client - server
    Stateless
    Cacheable
    Layered
    Uniform interface
    Discover. Master. Influence.
    6
  • 7. REST Constraints
    Uniform interface
    Client - server
    Stateless
    Cacheable
    Layered
    Discover. Master. Influence.
    7
  • 8. REST Benefits
    Scalability of component interactions
    Evolvability
    Reach
    Intermediary components to reduce latency, enforce security and encapsulate legacy systems
    Discover. Master. Influence.
    8
  • 9. RESTful Services-1
    A Traditional RPC based Service
    Moving from Verb to Noun
    Users
    Bookmarks
    Discover. Master. Influence.
    9
  • 10. RESTful Services-2
    Designing the Uri Template
    An invidual user account
    An individual bookmark
    A users collection of private/public bookmark
    Collection of all public bookmarks
    Applying the Uniform HTTP Interface
    Discover. Master. Influence.
    10
  • 11. RESTful Services-2
    11
    Discover. Master. Influence.
  • 12. RESTful Services-3
    Designing Resource Representation
    Discover. Master. Influence.
    12
  • 13. RESTful Services-4
    Designing Resource Representation

    < Email>aaron@pluralsight.com
    Aaron Skonnard

    Supporting Alternate Representation
    ?tag={tag}&format=json
    {username}?tag={tag}&format=json
    users/{username}?format=json
    users/{username}/profile?format=json
    Security Consideration
    Providing Resource Metadata
    Avoiding RPC Tendencies
    13
    Discover. Master. Influence.
  • 14. GET Example
    REQUEST
    GET /index.html
    Host: www.example.com
    RESPONSE
    HTTP/1.1 200 OK
    Etag: 3f80f-1b6-3e1cb03b
    Content-Type: text/html; charset=UTF-8
    l
    Discover. Master. Influence.
    14
  • 15. POST Example
    POST /order HTTP/1.1
    Host: amazon.net
    Content-Type: application/xml
    Content-Length: 216

    latte

    201 Created
    Location: http://amazon.net/order/1234
    ContentType: application/xml

    ...
    l
    Discover. Master. Influence.
    15
  • 16. PUT Example
    PUT /payment/1234 HTTP/1.1
    Host: amazon.net
    Content-Type: application/xml
    Content-Length: 216

    ...

    200 OK
    ContentType: application/vnd.amazon+xmlxmlns="http://schemas.amazon.net/order">
    Latte


    l
    Discover. Master. Influence.
    16
  • 17. Central Principle
    Existence of resource which is referenced with a global identifier (e.g. a image, document etc.)
    Communicate via a standard interface (e.g. HTTP)
    Exchange representations of these resources (HTML.XML,JSON etc.)
    Discover. Master. Influence.
    17
  • 18. RESTful web services
    Collection of data
    Base URI e.g. http://ebay.com/items/1
    Internet Media type of the data supported by the web service. (JSON,XML etc.)
    Set of operation supported by the web service using HTTP methods (POST,GET,PUT or DELETE)
    Discover. Master. Influence.
    18
  • 19. REST Using WCF
    Discover. Master. Influence.
  • 20. Rest Support Comparison
    Discover. Master. Influence.
    20
  • 21. WCF Web API
    HTTP is now a first class
    Content negotiation
    Automatic help pages
    Service Routes
    Integration with ASP.NET Caching
    Reach any client
    (Browser, Devices, Silverlight, Desktop)
    Discover. Master. Influence.
    21
  • 22. Resource
    Architecture
    Op Handler2
    Transport+Encoder
    Message Handler 1
    Response
    Discover. Master. Influence.
    22
    Dispatcher
    GetById?
    GetById?
    Op Handler 3
    Op Handler 4
    Op Handler 1
    Message Handler 2
    Request
  • 23. Components
    Content Negotiation
    Central Configuration (Fluent API)
    Http Classes
    Operation Handler Factory
    Error Handler
    Message Handler Factory(Channel Level)
    Discover. Master. Influence.
    23
  • 24. Classes for Request & Response
    • HttpRequestMessage
    • 25. HttpResponseMessage
    • 26. HttpContent
    • 27. HttpClient
    Discover. Master. Influence.
    24
  • 28. Content Negotiation
    Support for Multiple Formats including an add-in model
    if you want xml ,it gives xml and if you want Json, it gives Json
    Discover. Master. Influence.
    25
  • 29. Demo
    Content Negotiation
    Discover. Master. Influence.
  • 30. Operation Handler Factory
    Responsible for creating new instances of Media Type Formatters and Operation Handlers.
    Media Type Formatter
    Operation Handler - an abstract base class used to create transfer a set of input into a set of output
    Discover. Master. Influence.
    27
  • 31. Operation Handler Factory
    Request Pipeline
    Response Pipeline
    Operation Handler
    Operation Handler
    Operation Handler
    Operation Handler
    Operation Handler
    Operation Handler
    Dispatch
    Discover. Master. Influence.
    28
  • 32. Message Handler Factory
    Operation
    Message Handler4
    Message Handler3
    Message Handler 1
    Message Handler2
    Discover. Master. Influence.
    29
  • 33. Query Composition
    Support for OData like query support
    http://localhost/AlbumService/albums?$Top=5
    http://localhost/AlbumService/albums?$Top=5&$OrderBy=Title
    Discover. Master. Influence.
    30
  • 34. Consuming RESTful Services
    Consuming with Javascript
    Consuming with WCF
    31
    Discover. Master. Influence.
  • 35. Consuming Web API with Javascript
    32
    Discover. Master. Influence.
  • 36. HttpClient
    Helps you access web resources using Linq
    var client = new HttpClient(address);
    var personQuery = client.CreateQuery();
    var results = personQuery.ExecuteAsync().ContinueWith(p =>
    {
    //Dosomething here
    });
    Discover. Master. Influence.
    33
  • 37. Demo
    Query Composition & HttpClient
    Discover. Master. Influence.
  • 38. Questions?
    Discover. Master. Influence.