SlideShare une entreprise Scribd logo
1  sur  38
Christopher Bartling
Nick Spilman
Kevin Hakanson
Basic REST concepts

    Defining your Resource-oriented architecture

    HTTP status codes and error handling

    Content-type negotiation

    Using AJAX with REST

    Versioning REST APIs

    Caching and other performance

    considerations
REpresentational State Transfer

    Architecture style or design criteria

     Not a standard
    Stateless, client-server, cacheable

    communications protocol
    Use HTTP requests to post, read, and delete

    data.
    Lightweight

    Nouns as URI, verbs as HTTP method

Resource

     Anything that important enough to be referenced
      in its singularity
     Can be physical object or an abstract concept
     Every resource has at least one name
    Resources can be a container of other

    resources
     Containers are always resources
     Composite design pattern
Resource representation

     Any useful information about the state of a
      resource
     Specified through distinct URI or content
      negotiation through headers
    Canonical resource URI

     Independent of format or locale language
     Can be specified in Content-Location response
     header of representation response
GET

    http://www.example.com/v1/hr/employees/19328389

    POST

    http://www.example.com/v1/hr/employees

    DELETE

    http://www.example.com/v1/hr/employees/14283949

    PUT

    http://www.example.com/v1/hr/employees/13448784
Addressability

     Resources are identified by URIs
    Statelessness

     No connection state maintained between REST
      invocations
    Connectedness

     Resources should link together in their
      representations
    Uniform interface

     HTTP GET, PUT, POST, DELETE, HEAD, OPTIONS
     HTTP method header
     HTTP status codes
The name and address of a resource

     The scoping information to resources
     Principle of addressability
    Should be descriptive

    Unique URIs are exposed for every resource

    available from a RESTful system
     Every URI designates exactly one resource
    URIs are discoverable by your clients

No state stored on the server

    Every HTTP request executes in complete

    isolation on the server
    Simpler to design and evolve

    Easier to scale

    Avoid using HTTP sessions and cookies

    No side-effects

Standardized

       GET
       POST
       PUT
       DELETE
       HEAD
       OPTIONS
    Represents invocation action

    Resources expose uniform interface

Primary means of reporting the outcome of a

    REST operation
     Use the entity-body to add ancillary qualifiers to
      the outcome
     Do not send back resource representations for
      anything other than GET—negative impact on
      performance optimizations
    See Appendix B of RESTful Web Services

    book for top 42 HTTP status codes
GET and HEAD requests should not cause any

    disastrous changes to the server-side

    No side effects!

     Client should not be making requests just for the
     side effects

    Avoid exposing unsafe operations through

    GET
Multiple invocations of an operation results in

    the same result state as a single invocation

    Idempotent methods: GET, HEAD, PUT,

    DELETE , OPTIONS

    Not idempotent: POST

When creating and updating resources…

     PUT if, and only if, you can fully specify the full
      content of the resource
     POST if you are sending a command to create or
      update one or more subordinates of the specified
      resource
     With POST, the server will determine resource URI
    Use Location header in the POST response to

    specify new resource URI(s) if applicable
HTTPS and SSL certificate validation

    5 main HTTP methods

     GET, HEAD, POST, PUT, DELETE
    Customization of the data sent in the entity-

    body of a PUT or POST request
    Customization of HTTP headers

    Access to the response status code and

    headers
    Communicate through HTTP proxies

Transfer and handle compressed data

     Request: Accept-Encoding header
     Response: Encoding header
    Cache responses to requests

     Conditional GETs
    Common forms of HTTP authentication

     Basic, Digest, and WSSE
    Transparently follow HTTP redirects

Hierarchical

     Encode data into path variables on the URI
     http://maps.example.com/Earth/Europe/France/Paris
    No hierarchy

     Combine into one path variable, separated by
      commas or semicolons
     Use commas when order is important, semicolons
      when it doesn’t
     http://maps.example.com/Earth/24.9195,17.821
Algorithmic resources

     Use query variables
     http://www.google.com/search?q=rest
Version your services!



    Incorporate the version into the URI

     Set version to the first path variable
     GET /v1/users/34923408


    Representations should also be versioned

     Include version information in the representation
Most resources do not change much



    Saves client and server processing time and

    network bandwidth

    Implemented using HTTP headers

     Response headers: Last-Modified and ETag
     Request headers: If-Modified-Since and If-None-
     Match
Initial request for resource representation
Request

    GET /v1/users/10572 HTTP/1.1


    Response

    HTTP/1.1 200 OK
    Last-Modified: Mon, 13 Apr 2009 18:00:00 GMT
    ETag: 1239646841000
    Cache-Control: must-revalidate
    Expires: Thu, 01 Jan 1970 00:00:00 GMT
    Date: Mon, 13 Apr 2009 18:46:00 GMT
Subsequent requests for resource
representation
Request

    GET /v1/users/10572 HTTP/1.1
    If-Modified-Since: Mon, 13 Apr 2009 18:00:00 GMT
    If-None-Match: 1239646841000


    Response

    HTTP/1.1 304 Not Modified
    Date: Mon, 13 Apr 2009 18:47:00 GMT
Microsoft Internet Explorer

     Requires the Expires: -1 header
     Prevents caching in IE
     http://support.microsoft.com/kb/234067
Tools

     .NET
      ▪ Windows Communication Foundation (WCF)
     Java
      ▪ Spring MVC 3.0
      ▪ JAX-RS: CXF, Jersey, RESTEasy, RESTlet
    Design the REST API

     Don’t just let it happen!
     Seek out resources in your domain
Answer the following questions, in order:

    1. What are the URIs? What are the resources of
       your application?
    2. What is the representational format for the
       resources?
    3. What methods are supported at each URI?
    4. What status codes could be returned for each
       method?
Resources can be served in different

    representations
     XML, JSON, HTML, etc.
    Content negotiation methods

     Headers
      ▪ Accept or Content-Type
     Query parameter
      ▪ GET /v1/users/10572?format=json
     URI extension
      ▪ GET /v1/users/10572.xml
Tools

     Curl
     Apache HttpClient and JUnit
     Fiddler (Windows), HTTP Scoop (OS X), WireShark
Using REST as a RPC-like mechanism



    Overusing POST



    Putting actions in the URI



    Disguising a service as a resource



    Maintaining sessions on the server

RESTful Web Services. Leonard Richardson and Sam Ruby.

    http://jcalcote.wordpress.com/2008/10/16/put-or-post-the-rest-of-the-story/

    http://www.elharo.com/blog/software-development/web-development/2005/12/08/post-

    vs-put/
    http://www.xml.com/pub/a/2004/12/01/restful-web.html

    http://www.xml.com/pub/a/2004/03/17/udell.html

    http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm

    http://www.mozilla.org/projects/netlib/http/http-caching-faq.html

    http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html

RESTful Web Services

Contenu connexe

Tendances

Rest presentation
Rest  presentationRest  presentation
Rest presentation
srividhyau
 
RESTful services
RESTful servicesRESTful services
RESTful services
gouthamrv
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
habib_786
 

Tendances (20)

REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developers
 
Learn REST in 18 Slides
Learn REST in 18 SlidesLearn REST in 18 Slides
Learn REST in 18 Slides
 
Rest presentation
Rest  presentationRest  presentation
Rest presentation
 
API for Beginners
API for BeginnersAPI for Beginners
API for Beginners
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
Restful Web Services
Restful Web ServicesRestful Web Services
Restful Web Services
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
RESTful services
RESTful servicesRESTful services
RESTful services
 
Web api
Web apiWeb api
Web api
 
Introduction to API
Introduction to APIIntroduction to API
Introduction to API
 
introduction about REST API
introduction about REST APIintroduction about REST API
introduction about REST API
 
Rest API
Rest APIRest API
Rest API
 
Soap vs rest
Soap vs restSoap vs rest
Soap vs rest
 
Restful web services ppt
Restful web services pptRestful web services ppt
Restful web services ppt
 
Rest API Security
Rest API SecurityRest API Security
Rest API Security
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
API
APIAPI
API
 
Design Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIsDesign Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIs
 

En vedette (8)

REST Presentation
REST PresentationREST Presentation
REST Presentation
 
Some REST Design Patterns (and Anti-Patterns) - SOA Symposium 2009
Some REST Design Patterns (and Anti-Patterns) - SOA Symposium 2009Some REST Design Patterns (and Anti-Patterns) - SOA Symposium 2009
Some REST Design Patterns (and Anti-Patterns) - SOA Symposium 2009
 
Wsdl
WsdlWsdl
Wsdl
 
Nfc ppt
Nfc pptNfc ppt
Nfc ppt
 
NEAR FIELD COMMUNICATION
NEAR FIELD COMMUNICATIONNEAR FIELD COMMUNICATION
NEAR FIELD COMMUNICATION
 
NFC (Near Field Communication)
NFC (Near Field Communication)NFC (Near Field Communication)
NFC (Near Field Communication)
 
HyperText Transfer Protocol (HTTP)
HyperText Transfer Protocol (HTTP)HyperText Transfer Protocol (HTTP)
HyperText Transfer Protocol (HTTP)
 
Verb powerpoint
Verb powerpointVerb powerpoint
Verb powerpoint
 

Similaire à RESTful Web Services

RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
Li Yi
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
Carol McDonald
 

Similaire à RESTful Web Services (20)

01. http basics v27
01. http basics v2701. http basics v27
01. http basics v27
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
 
Doing REST Right
Doing REST RightDoing REST Right
Doing REST Right
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
 
Rest
RestRest
Rest
 
REST & RESTful Web Service
REST & RESTful Web ServiceREST & RESTful Web Service
REST & RESTful Web Service
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
Restful webservice
Restful webserviceRestful webservice
Restful webservice
 
A RESTful introduction
A RESTful introductionA RESTful introduction
A RESTful introduction
 
OpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Advisory Forum 2012 REST XML ResourcesOpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Advisory Forum 2012 REST XML Resources
 
Resource-Oriented Web Services
Resource-Oriented Web ServicesResource-Oriented Web Services
Resource-Oriented Web Services
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
KMUTNB - Internet Programming 2/7
KMUTNB - Internet Programming 2/7KMUTNB - Internet Programming 2/7
KMUTNB - Internet Programming 2/7
 
HTTP Basics Demo
HTTP Basics DemoHTTP Basics Demo
HTTP Basics Demo
 
Woa. Reloaded
Woa. ReloadedWoa. Reloaded
Woa. Reloaded
 
REST Introduction (PHP London)
REST Introduction (PHP London)REST Introduction (PHP London)
REST Introduction (PHP London)
 
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLEREST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
 
REST Easy with AngularJS - ng-grid CRUD Example
REST Easy with AngularJS - ng-grid CRUD ExampleREST Easy with AngularJS - ng-grid CRUD Example
REST Easy with AngularJS - ng-grid CRUD Example
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 

Plus de Christopher Bartling

Plus de Christopher Bartling (12)

JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
 
Acceptance Test-driven Development with Cucumber-jvm
Acceptance Test-driven Development with Cucumber-jvmAcceptance Test-driven Development with Cucumber-jvm
Acceptance Test-driven Development with Cucumber-jvm
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and KarmaJavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and Karma
 
Building Tropo Apps with Grails
Building Tropo Apps with GrailsBuilding Tropo Apps with Grails
Building Tropo Apps with Grails
 
CoffeeScript By Example
CoffeeScript By ExampleCoffeeScript By Example
CoffeeScript By Example
 
Acceptance Test Driven Development With Spec Flow And Friends
Acceptance Test Driven Development With Spec Flow And FriendsAcceptance Test Driven Development With Spec Flow And Friends
Acceptance Test Driven Development With Spec Flow And Friends
 
Introduction To Grails
Introduction To GrailsIntroduction To Grails
Introduction To Grails
 
Cucumber, Cuke4Duke, and Groovy
Cucumber, Cuke4Duke, and GroovyCucumber, Cuke4Duke, and Groovy
Cucumber, Cuke4Duke, and Groovy
 
Test Driven In Groovy
Test Driven In GroovyTest Driven In Groovy
Test Driven In Groovy
 
iPhone OS: The Next Killer Platform
iPhone OS: The Next Killer PlatformiPhone OS: The Next Killer Platform
iPhone OS: The Next Killer Platform
 
Grails Overview
Grails OverviewGrails Overview
Grails Overview
 
Rich Web Clients 20081118
Rich Web Clients 20081118Rich Web Clients 20081118
Rich Web Clients 20081118
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

RESTful Web Services

  • 2. Basic REST concepts  Defining your Resource-oriented architecture  HTTP status codes and error handling  Content-type negotiation  Using AJAX with REST  Versioning REST APIs  Caching and other performance  considerations
  • 3. REpresentational State Transfer  Architecture style or design criteria   Not a standard Stateless, client-server, cacheable  communications protocol Use HTTP requests to post, read, and delete  data. Lightweight  Nouns as URI, verbs as HTTP method 
  • 4. Resource   Anything that important enough to be referenced in its singularity  Can be physical object or an abstract concept  Every resource has at least one name Resources can be a container of other  resources  Containers are always resources  Composite design pattern
  • 5. Resource representation   Any useful information about the state of a resource  Specified through distinct URI or content negotiation through headers Canonical resource URI   Independent of format or locale language  Can be specified in Content-Location response header of representation response
  • 6. GET  http://www.example.com/v1/hr/employees/19328389 POST  http://www.example.com/v1/hr/employees DELETE  http://www.example.com/v1/hr/employees/14283949 PUT  http://www.example.com/v1/hr/employees/13448784
  • 7. Addressability   Resources are identified by URIs Statelessness   No connection state maintained between REST invocations Connectedness   Resources should link together in their representations Uniform interface   HTTP GET, PUT, POST, DELETE, HEAD, OPTIONS  HTTP method header  HTTP status codes
  • 8. The name and address of a resource   The scoping information to resources  Principle of addressability Should be descriptive  Unique URIs are exposed for every resource  available from a RESTful system  Every URI designates exactly one resource URIs are discoverable by your clients 
  • 9. No state stored on the server  Every HTTP request executes in complete  isolation on the server Simpler to design and evolve  Easier to scale  Avoid using HTTP sessions and cookies  No side-effects 
  • 10. Standardized   GET  POST  PUT  DELETE  HEAD  OPTIONS Represents invocation action  Resources expose uniform interface 
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16. Primary means of reporting the outcome of a  REST operation  Use the entity-body to add ancillary qualifiers to the outcome  Do not send back resource representations for anything other than GET—negative impact on performance optimizations See Appendix B of RESTful Web Services  book for top 42 HTTP status codes
  • 17. GET and HEAD requests should not cause any  disastrous changes to the server-side No side effects!   Client should not be making requests just for the side effects Avoid exposing unsafe operations through  GET
  • 18. Multiple invocations of an operation results in  the same result state as a single invocation Idempotent methods: GET, HEAD, PUT,  DELETE , OPTIONS Not idempotent: POST 
  • 19. When creating and updating resources…   PUT if, and only if, you can fully specify the full content of the resource  POST if you are sending a command to create or update one or more subordinates of the specified resource  With POST, the server will determine resource URI Use Location header in the POST response to  specify new resource URI(s) if applicable
  • 20. HTTPS and SSL certificate validation  5 main HTTP methods   GET, HEAD, POST, PUT, DELETE Customization of the data sent in the entity-  body of a PUT or POST request Customization of HTTP headers  Access to the response status code and  headers Communicate through HTTP proxies 
  • 21. Transfer and handle compressed data   Request: Accept-Encoding header  Response: Encoding header Cache responses to requests   Conditional GETs Common forms of HTTP authentication   Basic, Digest, and WSSE Transparently follow HTTP redirects 
  • 22. Hierarchical   Encode data into path variables on the URI  http://maps.example.com/Earth/Europe/France/Paris No hierarchy   Combine into one path variable, separated by commas or semicolons  Use commas when order is important, semicolons when it doesn’t  http://maps.example.com/Earth/24.9195,17.821
  • 23. Algorithmic resources   Use query variables  http://www.google.com/search?q=rest
  • 24. Version your services!  Incorporate the version into the URI   Set version to the first path variable  GET /v1/users/34923408 Representations should also be versioned   Include version information in the representation
  • 25. Most resources do not change much  Saves client and server processing time and  network bandwidth Implemented using HTTP headers   Response headers: Last-Modified and ETag  Request headers: If-Modified-Since and If-None- Match
  • 26. Initial request for resource representation
  • 27. Request  GET /v1/users/10572 HTTP/1.1 Response  HTTP/1.1 200 OK Last-Modified: Mon, 13 Apr 2009 18:00:00 GMT ETag: 1239646841000 Cache-Control: must-revalidate Expires: Thu, 01 Jan 1970 00:00:00 GMT Date: Mon, 13 Apr 2009 18:46:00 GMT
  • 28. Subsequent requests for resource representation
  • 29. Request  GET /v1/users/10572 HTTP/1.1 If-Modified-Since: Mon, 13 Apr 2009 18:00:00 GMT If-None-Match: 1239646841000 Response  HTTP/1.1 304 Not Modified Date: Mon, 13 Apr 2009 18:47:00 GMT
  • 30. Microsoft Internet Explorer   Requires the Expires: -1 header  Prevents caching in IE http://support.microsoft.com/kb/234067
  • 31. Tools   .NET ▪ Windows Communication Foundation (WCF)  Java ▪ Spring MVC 3.0 ▪ JAX-RS: CXF, Jersey, RESTEasy, RESTlet Design the REST API   Don’t just let it happen!  Seek out resources in your domain
  • 32. Answer the following questions, in order:  1. What are the URIs? What are the resources of your application? 2. What is the representational format for the resources? 3. What methods are supported at each URI? 4. What status codes could be returned for each method?
  • 33. Resources can be served in different  representations  XML, JSON, HTML, etc. Content negotiation methods   Headers ▪ Accept or Content-Type  Query parameter ▪ GET /v1/users/10572?format=json  URI extension ▪ GET /v1/users/10572.xml
  • 34. Tools   Curl  Apache HttpClient and JUnit  Fiddler (Windows), HTTP Scoop (OS X), WireShark
  • 35. Using REST as a RPC-like mechanism  Overusing POST  Putting actions in the URI  Disguising a service as a resource  Maintaining sessions on the server 
  • 36.
  • 37. RESTful Web Services. Leonard Richardson and Sam Ruby.  http://jcalcote.wordpress.com/2008/10/16/put-or-post-the-rest-of-the-story/  http://www.elharo.com/blog/software-development/web-development/2005/12/08/post-  vs-put/ http://www.xml.com/pub/a/2004/12/01/restful-web.html  http://www.xml.com/pub/a/2004/03/17/udell.html  http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm  http://www.mozilla.org/projects/netlib/http/http-caching-faq.html  http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html 