REST
Assured
Yaniv Rodenski
Senior Consultant, Sela Group

http://blogs.microsoft.co.il/blogs/roadan
Twitter: @YRodenski
A brief history of The Web API




                        March 2012
                                               ASP.NET is
                                               Open Source
6 Preview Versions
                     Fab 2012
                                      ASP.NET Web
                                      API (Beta)
         October 2010
                                WCF Web API
                                on Code Plex
State of the web
• Today the web faces new challenges:
  – Internet scale applications



  – Cloud operating systems
State of the web
• Today the web faces new challenges:
  – Even more complex integrations
State of the web
• Today the web faces new challenges:
  – Broader reach of clients
Agenda

• Basic terminology
• REST via the ASP.NET Web API
  – Richardson maturity model
  – Hypermedia Patterns
  – Media types
• Caching
SOAP
• Promise to add “object access”-like semantics to the
  web
   – Operation centric
   – Uses a large message format
• Extensible
   – Over the years a large amount of extending standards
     were created (AKA WS-*)
   – By extension, adds stateful semantics over the web
• Promotes the use of the proxy pattern
• Not web natural
• Supported by major development environments
SOAP Service calls

• Request




• Response
HTTP
• Promise to transfer hypertext
• The primal and most native protocol of the
  web
• Stateless
• Supported by almost any device on the face of
  the earth
HTTP Service calls
• Request



• Response
SOA
• SOA is an architectural approach for
  distributed systems
• SOA defines four tenets focusing on service
  autonomy and boundaries
• SOA is a fully mature architecture with well-
  known patterns and solutions for complex
  communication and integration scenarios
REST
• The term Representational State Transfer
  (REST) was coined by Roy Fielding in his Ph.D.
  thesis in 2000
• An architectural style that embraces HTTP and
  the World Wide Web
• Web friendly
Richardson maturity model
• Leonard Richardson’s maturity model
  describes four levels of service maturity


                       Hypermedia

                          Http

                        Resources
RMM – Level zero services
• Level zero services do not use HTTP as an application
  protocol.
• Use HTTP as a transport for other remote interaction
  mechanism




                                               Hypermedia

                                                  Http

                                                Resources
RMM – Level one services
• Level one services acknowledge resources
• Resources are accessed via a unique address (formatted as a
  Universal Resource Identifier)
• When accessed, a resource returns a representation

http://myfooty.com/players/henrique
http://myfooty.com/players/neymar




                                                      Hypermedia

                                                         Http

                                                      Resources
Level one service
Web neutrality
• In his famous 2001 bath-tub talk Don Box
  drew the line between web pages and web
  services by defining their consuming life
  forms:




      Carbon based            Silicon based
         Web Pages              Web Services
RMM – Level two services
• Level two services use HTTP mechanisms
  properly:
  – Verbs
  – Status codes
  – Headers



                                      Hypermedia

                                           Http

                                       Resources
HTTP verbs
• HTTP defines different methods (sometimes
  called verbs) to indicate a desired action to be
  performed on a resource
• These verbs define a common terminology
  that is accepted by users, developers and the
  infrastructure of the World Wide Web
Using HTTP verbs for CRUD
HTTP status codes
• In addition to a response message, HTTP uses
  status codes to communicate to the clients the
  resultant status of the operation
• The first digit of the status code specifies one of
  five classes of response:
   –   1xx Informational
   –   2xx Success
   –   3xx Redirection
   –   4xx Client Error
   –   5xx Server Error
HTTP headers
• HTTP uses headers to transfer metadata
  regarding the message’s content and transport
• HTTP headers are one of HTTP’s main
  extensibility points
Level Two Service
RMM – Level three services
• Level one and two services deal with
  resources which represent entities
• Level three services introduce flow
  management via hypermedia controls (For
  example: links)


                                      Hypermedia

                                         Http

                                      Resources
RMM – Level three services
• Hypermedia is used as a logical extension of
  the term hypertext in which graphics, audio,
  video, plain text and hyperlinks intertwine to
  create a generally non-linear medium of
  information.
                 http://en.wikipedia.org/wiki/Hypermedia



                                                           Hypermedia

                                                              Http

                                                           Resources
Hypermedia Application
Hypermedia Patterns

• Hypermedia can be used to express different
  behaviors in an application:
  – Control flow management (State machine)
  – Discoverability and versioning
  – Properties management
  – Aspect management
  – Paging
OData paging
Media types (MIME)

• HTTP media types are used to describe the
  format of the message body
• In REST media types are used describe
  representations, hypermedia controls, and
  processing rules
• By creating a media type we can define the
  application’s domain
Using Media Formatters
Cache the REST
• HTTP caches can store copies of the responses
  along the request response path to reduce
  network traffic
• HTTP caches reduces call latency
• Caches are a main factor for scalability on the
  web
Types of Cache
• Browser Cache
 Stores representations locally on the computer’s hard drive
• Proxy Cache
 Corporates and ISPs provide shared proxies providing shared cache
 on their network
• Gateway (Reverse Proxy) Cache
 Stores representations on behalf of the server. Content Delivery
 Networks (CDNs) use gateway cache distributed around the web
Controlling Cache
• HTTP headers can be used to control cache
  behaviors
• HTTP provides method the avoid staleness of
  cached data
  – Expiration
  – Validation
Controlling Cache Behavior
Summary
• HTTP is a powerful application level protocol
• Built to serve the worlds largest information
  system
• REST provides an architecture that enables
  better use of the inherent scaling capabilities of
  the web
• Hypermedia enables us to scale and grow our
  application
My Blog                                                           ASP.NET Web APIs
http://bit.ly/roadan                                              http://www.asp.net/web-api/
(best viewed from multiple ip addresses)


Architectural Styles and the Design of                            HTTP/1.1 Specifications
                                                                  http://www.w3.org/Protocols/
Network-based Software Architectures
Roy Fielding
http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm
                                                                  REST in practice (Book)
                                                                  http://restinpractice.com/default.aspx
Debugging the web with Fiddler
Ido Flatow
http://scc.sela.co.il/SCC/Pages/ShowLecture/ShowLecture.aspx?lectureId=642

Rest assured

  • 1.
    REST Assured Yaniv Rodenski Senior Consultant,Sela Group http://blogs.microsoft.co.il/blogs/roadan Twitter: @YRodenski
  • 2.
    A brief historyof The Web API March 2012 ASP.NET is Open Source 6 Preview Versions Fab 2012 ASP.NET Web API (Beta) October 2010 WCF Web API on Code Plex
  • 4.
    State of theweb • Today the web faces new challenges: – Internet scale applications – Cloud operating systems
  • 5.
    State of theweb • Today the web faces new challenges: – Even more complex integrations
  • 6.
    State of theweb • Today the web faces new challenges: – Broader reach of clients
  • 7.
    Agenda • Basic terminology •REST via the ASP.NET Web API – Richardson maturity model – Hypermedia Patterns – Media types • Caching
  • 8.
    SOAP • Promise toadd “object access”-like semantics to the web – Operation centric – Uses a large message format • Extensible – Over the years a large amount of extending standards were created (AKA WS-*) – By extension, adds stateful semantics over the web • Promotes the use of the proxy pattern • Not web natural • Supported by major development environments
  • 9.
    SOAP Service calls •Request • Response
  • 10.
    HTTP • Promise totransfer hypertext • The primal and most native protocol of the web • Stateless • Supported by almost any device on the face of the earth
  • 11.
    HTTP Service calls •Request • Response
  • 12.
    SOA • SOA isan architectural approach for distributed systems • SOA defines four tenets focusing on service autonomy and boundaries • SOA is a fully mature architecture with well- known patterns and solutions for complex communication and integration scenarios
  • 13.
    REST • The termRepresentational State Transfer (REST) was coined by Roy Fielding in his Ph.D. thesis in 2000 • An architectural style that embraces HTTP and the World Wide Web • Web friendly
  • 14.
    Richardson maturity model •Leonard Richardson’s maturity model describes four levels of service maturity Hypermedia Http Resources
  • 15.
    RMM – Levelzero services • Level zero services do not use HTTP as an application protocol. • Use HTTP as a transport for other remote interaction mechanism Hypermedia Http Resources
  • 16.
    RMM – Levelone services • Level one services acknowledge resources • Resources are accessed via a unique address (formatted as a Universal Resource Identifier) • When accessed, a resource returns a representation http://myfooty.com/players/henrique http://myfooty.com/players/neymar Hypermedia Http Resources
  • 17.
  • 18.
    Web neutrality • Inhis famous 2001 bath-tub talk Don Box drew the line between web pages and web services by defining their consuming life forms: Carbon based Silicon based Web Pages Web Services
  • 19.
    RMM – Leveltwo services • Level two services use HTTP mechanisms properly: – Verbs – Status codes – Headers Hypermedia Http Resources
  • 20.
    HTTP verbs • HTTPdefines different methods (sometimes called verbs) to indicate a desired action to be performed on a resource • These verbs define a common terminology that is accepted by users, developers and the infrastructure of the World Wide Web
  • 21.
  • 22.
    HTTP status codes •In addition to a response message, HTTP uses status codes to communicate to the clients the resultant status of the operation • The first digit of the status code specifies one of five classes of response: – 1xx Informational – 2xx Success – 3xx Redirection – 4xx Client Error – 5xx Server Error
  • 23.
    HTTP headers • HTTPuses headers to transfer metadata regarding the message’s content and transport • HTTP headers are one of HTTP’s main extensibility points
  • 24.
  • 25.
    RMM – Levelthree services • Level one and two services deal with resources which represent entities • Level three services introduce flow management via hypermedia controls (For example: links) Hypermedia Http Resources
  • 26.
    RMM – Levelthree services • Hypermedia is used as a logical extension of the term hypertext in which graphics, audio, video, plain text and hyperlinks intertwine to create a generally non-linear medium of information. http://en.wikipedia.org/wiki/Hypermedia Hypermedia Http Resources
  • 27.
  • 28.
    Hypermedia Patterns • Hypermediacan be used to express different behaviors in an application: – Control flow management (State machine) – Discoverability and versioning – Properties management – Aspect management – Paging
  • 29.
  • 30.
    Media types (MIME) •HTTP media types are used to describe the format of the message body • In REST media types are used describe representations, hypermedia controls, and processing rules • By creating a media type we can define the application’s domain
  • 31.
  • 32.
    Cache the REST •HTTP caches can store copies of the responses along the request response path to reduce network traffic • HTTP caches reduces call latency • Caches are a main factor for scalability on the web
  • 33.
    Types of Cache •Browser Cache Stores representations locally on the computer’s hard drive • Proxy Cache Corporates and ISPs provide shared proxies providing shared cache on their network • Gateway (Reverse Proxy) Cache Stores representations on behalf of the server. Content Delivery Networks (CDNs) use gateway cache distributed around the web
  • 34.
    Controlling Cache • HTTPheaders can be used to control cache behaviors • HTTP provides method the avoid staleness of cached data – Expiration – Validation
  • 35.
  • 36.
    Summary • HTTP isa powerful application level protocol • Built to serve the worlds largest information system • REST provides an architecture that enables better use of the inherent scaling capabilities of the web • Hypermedia enables us to scale and grow our application
  • 38.
    My Blog ASP.NET Web APIs http://bit.ly/roadan http://www.asp.net/web-api/ (best viewed from multiple ip addresses) Architectural Styles and the Design of HTTP/1.1 Specifications http://www.w3.org/Protocols/ Network-based Software Architectures Roy Fielding http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm REST in practice (Book) http://restinpractice.com/default.aspx Debugging the web with Fiddler Ido Flatow http://scc.sela.co.il/SCC/Pages/ShowLecture/ShowLecture.aspx?lectureId=642

Editor's Notes

  • #11 Focuses on improving web communication by using mechanizes like caching, ETags, the TRACE verb etc.
  • #14 Focuses on improving web communication by using mechanizes like caching, ETags, the TRACE verb etc.
  • #17 This model allows a resource to manage its own state while the client manages the application stateRepresentations can also be cached
  • #19 The “web” uses resources and their representations for caching and scalability.Resources prevent the need to dibranchiate web pages and services
  • #26 This model allows a resource to manage its own state while the client manages the application state
  • #27 This model allows a resource to manage its own state while the client manages the application state