SlideShare une entreprise Scribd logo
1  sur  22
Télécharger pour lire hors ligne
PyCon 2010, Atlanta


    Creating RESTful Web Services
              with restish

           Grig Gheorghiu
                Evite

       grig.gheorghiu@evite.com


                   
Credits

       Roy Fielding Ph.D. Dissertation
       'RESTful Web Services' book by L. Richardson 
        and S. Ruby (O'Reilly)
       Joe Gregorio's REST articles for xml.com
       Mark Pilgrim's Web services tutorial in 'Dive into 
        Python'
       Mark Nottingham's Web caching tutorials

                                
What is a web service?
       Specific kind of Web application
       Consumed by applications, not directly by 
        humans/browsers
       Typically emits XML or JSON and not HTML
       Examples: Amazon Web Services (S3, SQS, 
        EC2), Yahoo Web Services (del.icio.us, Flickr)
       'Programmable Web': 
        http://www.programmableweb.com/apis/directory/


                                       
What is REST?
       ”REpresentational StateTransfer”: Roy Fielding, 
        Ph.D. Dissertation, UC Irvine, 2000
       'Architectural style for distributed hypermedia 
        systems'; start with NULL style and add 
        constraints:
           Client­Server
           Stateless
           Cache
           Uniform Interface
 
           Layered System       
HTTP crash course
       Requests and responses
       HTTP request: a method (GET, POST, PUT, 
        DELETE, HEAD), a path (/index.html), a set of 
        headers, and the entity­body (representation)
       HTTP response: a response code (200, 404, 
        etc.), a set of headers, and the entity­body 
        (representation)
       Lingua franca of the Internet

                                
Web architectures
       REST(ful)
           Based on HTTP methods (GET, POST, PUT, DELETE)
           Arguments to methods go in URIs or in HTTP payloads
           Amazon S3, last.fm API
       RPC­style (SOAP, XML­RPC)
           Typically one single URI is exposed
           Heavy on POST operations
       Hybrid REST­RPC
           Overloaded GET used to modify data
           Bad idea (remember Google Web Accelerator?)
                                   
Resource­Oriented Architecture
       Leonard Richardson and Sam Ruby
       4 concepts: resources, their names, their 
        representations, the links between them
       4 properties: addressability, statelessnes, 
        connectedness, uniform interface




                                
Resources and URIs
       Resource == anything that is important enough 
        to be referenced (or linked to)
       Comparable to objects in OO design
       Every resource has a 'name': URI == Uniform 
        Resource Identifier
       1 resource → N URIs
       Examples of URIs:
           URL(ocator): http://socal­piggies.org/scp
           URN(ame): urn:isbn:0­395­36341­1
                                    
Representations and links
       Representation == concrete data which 
        describes the current state of a resource
           Example: description of the most recent bug
       In practice: a specific data format (XML, JSON, 
        etc)
       Client­server state transfer happens by 
        exchange of representations (hence 
        ”REpresentational State Transfer”)
       Server guides client from one state to another 
        by means of links embedded in representations
                                 
Addressability
       Resources exposed as URIs are addressable
           Can be linked to
           Can be bookmarked
           Can be printed in a book
           Can be sent in an email
           Can be cached
       Openness vs. Opacity; REST vs. RPC
       Think 'mashups'!

                                   
Statelessness
       Each HTTP request contains all the state it 
        needs for the server to fulfil it
       State is only on the client side!
       Server can nudge client to different states via 
        links (connectedness)
       Statelessness induces:
           Visibility: each request can be monitored in isolation
           Reliability: easier to recover from partial failures
           Scalability: easy to scale horizontally
                                      
The Uniform Interface
       Methods dictated by HTTP verbs (uniformity)
                                        uniformity
       CRUD operations
           Create: POST/PUT
           Retrieve: GET (HEAD for resource metadata)
           Update: PUT
           Delete: DELETE
       GET and HEAD should be safe (no changes to 
        server state)
       GET, HEAD, PUT should be idempotent
                                  
So...why REST?
       Client­Server (Web client ↔ Web server)
       Stateless (client keeps state)
       Uniform interface (HTTP methods)
       Caching
           Reduces latency
           Reduces network bandwidth
       Layered system (higher application layer calls 
        lower Web services layer)
                                 
HTTP caching in a nutshell
    Special HTTP headers
    Server: freshness indicators (”it's safe to 
     cache”)
        Cache­control → absolute date/time
        Expires → delta relative to time of request
    Server: validators (”is it still safe to cache?”)
        Last­Modified → absolute date/time
        Etag → hash of content
    Client: If­Modified­Since (for Last­Modified)
 
     Client: If­None­Match (for Etag)
                             
Creating a RESTful service
       Joe Gregorio article ”How to create a REST 
        protocol”
       To create a REST service, you need to answer 
        the following questions, and you should answer 
        them in this order:
           What are the URIs? (resources)
           What's the format? (representations)
           What methods are supported at each URI?
           What status codes could be returned?
                                   
Introducing the restish framework
       Created by Tim Parkin and Matt Goodall
       Part of the 'ish' family of tools at
        http://github.com/ish
            Formish
            Adminish
            Couchish
       Example site developed with restish: 
        www.profiled.com

                                  
Why restish?
       Close­to­the­metal, REST­oriented, WSGI 
        aware
       Well tested and powerful URL handling, parsing 
        and creation
       Powerful but simple HTTP request and 
        response handling (based on WebOb)
       Simple integration with templating frameworks 
        (mako, jinja2, genshi, django)
       Basic HTTP auth via guard module (e.g. using 
        repoze.who as WSGI middleware)
                              
Demo app: todoish list mgmt
       What are the URIs? (resources)
           /lists/LISTID/items/ITEMID
       What's the format? (representations)
           JSON
       What methods are supported at each URI?
           POST, PUT, GET
       What status codes could be returned?
           Success: 200 OK, 201 Created
           Error: 404 Not Found, 501 Not Implemented
                                   
Consuming Web services
       Curl
curl -i -X POST 127.0.0.1:9999/lists/ -H "Content-
Type: application/json" -d '{"name":"new list"}'
       Httplib2




                           
Testing a restish Web app
       Unit testing: WebTest
       Functional testing: twill (for HTML 
        representations)




                                 
Deploying a restish Web app
       Run web application process properly as a 
        daemon (e.g. using grizzled.os)
       Use log rotation (rotatelogs, scribe)
       Use automated deployment tools (fabric)
       Use robust reverse proxy/load balancer (e.g. 
        nginx)




                                
What should you take away?

       blah blah blah RESOURCES blah blah blah 
        HTTP UNIFORM INTERFACE blah blah 
        STATELESSNESS blah blah JSON/XML blah 
        blah RESTISH blah blah TESTING blah blah 
        AUTOMATED DEPLOYMENTS blah blah 
        EVITE IS HIRING PYTHON PROGRAMMERS




                            

Contenu connexe

Tendances

Cwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey IntroductionseyCwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey Introductionseyelliando dias
 
Rest presentation
Rest  presentationRest  presentation
Rest presentationsrividhyau
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jerseyb_kathir
 
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRISThe glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRISGeert Pante
 
Restful web services by Sreeni Inturi
Restful web services by Sreeni InturiRestful web services by Sreeni Inturi
Restful web services by Sreeni InturiSreeni I
 
Restful webservice
Restful webserviceRestful webservice
Restful webserviceDong Ngoc
 
HATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from RESTHATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from RESTelliando dias
 
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India
 
Rest and the hypermedia constraint
Rest and the hypermedia constraintRest and the hypermedia constraint
Rest and the hypermedia constraintInviqa
 
REST - Representational state transfer
REST - Representational state transferREST - Representational state transfer
REST - Representational state transferTricode (part of Dept)
 
Webservices Overview : XML RPC, SOAP and REST
Webservices Overview : XML RPC, SOAP and RESTWebservices Overview : XML RPC, SOAP and REST
Webservices Overview : XML RPC, SOAP and RESTPradeep Kumar
 
Soap and restful webservice
Soap and restful webserviceSoap and restful webservice
Soap and restful webserviceDong Ngoc
 
Spring HATEOAS
Spring HATEOASSpring HATEOAS
Spring HATEOASYoann Buch
 

Tendances (20)

Cwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey IntroductionseyCwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey Introductionsey
 
Rest presentation
Rest  presentationRest  presentation
Rest presentation
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
 
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRISThe glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
 
Restful web services by Sreeni Inturi
Restful web services by Sreeni InturiRestful web services by Sreeni Inturi
Restful web services by Sreeni Inturi
 
Restful web services ppt
Restful web services pptRestful web services ppt
Restful web services ppt
 
SOAP-based Web Services
SOAP-based Web ServicesSOAP-based Web Services
SOAP-based Web Services
 
Restful webservice
Restful webserviceRestful webservice
Restful webservice
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
HATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from RESTHATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from REST
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
 
Rest and the hypermedia constraint
Rest and the hypermedia constraintRest and the hypermedia constraint
Rest and the hypermedia constraint
 
REST - Representational state transfer
REST - Representational state transferREST - Representational state transfer
REST - Representational state transfer
 
Webservices Overview : XML RPC, SOAP and REST
Webservices Overview : XML RPC, SOAP and RESTWebservices Overview : XML RPC, SOAP and REST
Webservices Overview : XML RPC, SOAP and REST
 
Soap and Rest
Soap and RestSoap and Rest
Soap and Rest
 
Soap and restful webservice
Soap and restful webserviceSoap and restful webservice
Soap and restful webservice
 
JSON and REST
JSON and RESTJSON and REST
JSON and REST
 
Spring HATEOAS
Spring HATEOASSpring HATEOAS
Spring HATEOAS
 
Rest web services
Rest web servicesRest web services
Rest web services
 

En vedette

Digital Transformation in a World of Connected Devices
Digital Transformation in a World of Connected DevicesDigital Transformation in a World of Connected Devices
Digital Transformation in a World of Connected DevicesMuleSoft
 
APIs in a .NET World
APIs in a .NET WorldAPIs in a .NET World
APIs in a .NET WorldMuleSoft
 
Innovation In The Era of Cloud Applications and Services
Innovation In The Era of Cloud Applications and ServicesInnovation In The Era of Cloud Applications and Services
Innovation In The Era of Cloud Applications and ServicesMuleSoft
 
CIO Panel: Digital Transformation to Achieve Speed and Control
CIO Panel: Digital Transformation to Achieve Speed and ControlCIO Panel: Digital Transformation to Achieve Speed and Control
CIO Panel: Digital Transformation to Achieve Speed and ControlMuleSoft
 
Launch Mobile Applications with Speed While Maintaining Control
Launch Mobile Applications with Speed While Maintaining ControlLaunch Mobile Applications with Speed While Maintaining Control
Launch Mobile Applications with Speed While Maintaining ControlMuleSoft
 
Product Keynote: How to Compete in the API Economy
Product Keynote: How to Compete in the API EconomyProduct Keynote: How to Compete in the API Economy
Product Keynote: How to Compete in the API EconomyMuleSoft
 
Transform Your Business with API-led Connectivity
Transform Your Business with API-led ConnectivityTransform Your Business with API-led Connectivity
Transform Your Business with API-led ConnectivityMuleSoft
 
Connecting the New Enterprise | MuleSoft
Connecting the New Enterprise | MuleSoftConnecting the New Enterprise | MuleSoft
Connecting the New Enterprise | MuleSoftMuleSoft
 
The Blueprint for Change: How the Best Are Succeeding in Transformation
The Blueprint for Change: How the Best Are Succeeding in TransformationThe Blueprint for Change: How the Best Are Succeeding in Transformation
The Blueprint for Change: How the Best Are Succeeding in TransformationMuleSoft
 
Why Integrate using an API? | MuleSoft
Why Integrate using an API? | MuleSoftWhy Integrate using an API? | MuleSoft
Why Integrate using an API? | MuleSoftMuleSoft
 
Guide to Application Performance: Planning to Continued Optimization
Guide to Application Performance: Planning to Continued OptimizationGuide to Application Performance: Planning to Continued Optimization
Guide to Application Performance: Planning to Continued OptimizationMuleSoft
 
Rethinking it for digital transformation
Rethinking it for digital transformationRethinking it for digital transformation
Rethinking it for digital transformationMuleSoft
 
Best Practices for API Security
Best Practices for API SecurityBest Practices for API Security
Best Practices for API SecurityMuleSoft
 
Future of Integration | MuleSoft
Future of Integration | MuleSoftFuture of Integration | MuleSoft
Future of Integration | MuleSoftMuleSoft
 
Application Architecture: The Next Wave | MuleSoft
Application Architecture: The Next Wave | MuleSoftApplication Architecture: The Next Wave | MuleSoft
Application Architecture: The Next Wave | MuleSoftMuleSoft
 
Digital Businesses of the Future
Digital Businesses of the Future Digital Businesses of the Future
Digital Businesses of the Future MuleSoft
 
Welcome to the API Economy: Developing Your API Strategy
Welcome to the API Economy: Developing Your API StrategyWelcome to the API Economy: Developing Your API Strategy
Welcome to the API Economy: Developing Your API StrategyMuleSoft
 

En vedette (19)

Digital Transformation in a World of Connected Devices
Digital Transformation in a World of Connected DevicesDigital Transformation in a World of Connected Devices
Digital Transformation in a World of Connected Devices
 
APIs in a .NET World
APIs in a .NET WorldAPIs in a .NET World
APIs in a .NET World
 
Investor Presentation
Investor PresentationInvestor Presentation
Investor Presentation
 
Innovation In The Era of Cloud Applications and Services
Innovation In The Era of Cloud Applications and ServicesInnovation In The Era of Cloud Applications and Services
Innovation In The Era of Cloud Applications and Services
 
CIO Panel: Digital Transformation to Achieve Speed and Control
CIO Panel: Digital Transformation to Achieve Speed and ControlCIO Panel: Digital Transformation to Achieve Speed and Control
CIO Panel: Digital Transformation to Achieve Speed and Control
 
Launch Mobile Applications with Speed While Maintaining Control
Launch Mobile Applications with Speed While Maintaining ControlLaunch Mobile Applications with Speed While Maintaining Control
Launch Mobile Applications with Speed While Maintaining Control
 
Product Keynote: How to Compete in the API Economy
Product Keynote: How to Compete in the API EconomyProduct Keynote: How to Compete in the API Economy
Product Keynote: How to Compete in the API Economy
 
MAX-CONNECT launches MAX-Jobs
MAX-CONNECT launches MAX-JobsMAX-CONNECT launches MAX-Jobs
MAX-CONNECT launches MAX-Jobs
 
Transform Your Business with API-led Connectivity
Transform Your Business with API-led ConnectivityTransform Your Business with API-led Connectivity
Transform Your Business with API-led Connectivity
 
Connecting the New Enterprise | MuleSoft
Connecting the New Enterprise | MuleSoftConnecting the New Enterprise | MuleSoft
Connecting the New Enterprise | MuleSoft
 
The Blueprint for Change: How the Best Are Succeeding in Transformation
The Blueprint for Change: How the Best Are Succeeding in TransformationThe Blueprint for Change: How the Best Are Succeeding in Transformation
The Blueprint for Change: How the Best Are Succeeding in Transformation
 
Why Integrate using an API? | MuleSoft
Why Integrate using an API? | MuleSoftWhy Integrate using an API? | MuleSoft
Why Integrate using an API? | MuleSoft
 
Guide to Application Performance: Planning to Continued Optimization
Guide to Application Performance: Planning to Continued OptimizationGuide to Application Performance: Planning to Continued Optimization
Guide to Application Performance: Planning to Continued Optimization
 
Rethinking it for digital transformation
Rethinking it for digital transformationRethinking it for digital transformation
Rethinking it for digital transformation
 
Best Practices for API Security
Best Practices for API SecurityBest Practices for API Security
Best Practices for API Security
 
Future of Integration | MuleSoft
Future of Integration | MuleSoftFuture of Integration | MuleSoft
Future of Integration | MuleSoft
 
Application Architecture: The Next Wave | MuleSoft
Application Architecture: The Next Wave | MuleSoftApplication Architecture: The Next Wave | MuleSoft
Application Architecture: The Next Wave | MuleSoft
 
Digital Businesses of the Future
Digital Businesses of the Future Digital Businesses of the Future
Digital Businesses of the Future
 
Welcome to the API Economy: Developing Your API Strategy
Welcome to the API Economy: Developing Your API StrategyWelcome to the API Economy: Developing Your API Strategy
Welcome to the API Economy: Developing Your API Strategy
 

Similaire à PyCon 2010 REST Talk

Introduction to REST and the Restlet Framework
Introduction to REST and the Restlet FrameworkIntroduction to REST and the Restlet Framework
Introduction to REST and the Restlet FrameworkPhilip Johnson
 
Introduction to REST and Jersey
Introduction to REST and JerseyIntroduction to REST and Jersey
Introduction to REST and JerseyChris Winters
 
RESTFul WebApp Concept
RESTFul WebApp ConceptRESTFul WebApp Concept
RESTFul WebApp ConceptDian Aditya
 
RESTFul WebApp Concept
RESTFul WebApp ConceptRESTFul WebApp Concept
RESTFul WebApp ConceptDian Aditya
 
Separating REST Facts from Fallacies
Separating REST Facts from FallaciesSeparating REST Facts from Fallacies
Separating REST Facts from FallaciesAlan Dean
 
The RESTful Soa Datagrid with Oracle
The RESTful Soa Datagrid with OracleThe RESTful Soa Datagrid with Oracle
The RESTful Soa Datagrid with OracleEmiliano Pecis
 
RESTful services
RESTful servicesRESTful services
RESTful servicesgouthamrv
 
Дмитрий Красун: Сегодня вы уйдете с новым представлением о REST
Дмитрий Красун: Сегодня вы уйдете с новым представлением о RESTДмитрий Красун: Сегодня вы уйдете с новым представлением о REST
Дмитрий Красун: Сегодня вы уйдете с новым представлением о RESTOleg Poludnenko
 
Network Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyNetwork Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyPayal Jain
 
Restful web services rule financial
Restful web services   rule financialRestful web services   rule financial
Restful web services rule financialRule_Financial
 

Similaire à PyCon 2010 REST Talk (20)

Introduction to REST and the Restlet Framework
Introduction to REST and the Restlet FrameworkIntroduction to REST and the Restlet Framework
Introduction to REST and the Restlet Framework
 
Salesforce REST API
Salesforce  REST API Salesforce  REST API
Salesforce REST API
 
Modified REST Presentation
Modified REST PresentationModified REST Presentation
Modified REST Presentation
 
Introduction to REST and Jersey
Introduction to REST and JerseyIntroduction to REST and Jersey
Introduction to REST and Jersey
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
RESTFul WebApp Concept
RESTFul WebApp ConceptRESTFul WebApp Concept
RESTFul WebApp Concept
 
RESTFul WebApp Concept
RESTFul WebApp ConceptRESTFul WebApp Concept
RESTFul WebApp Concept
 
Separating REST Facts from Fallacies
Separating REST Facts from FallaciesSeparating REST Facts from Fallacies
Separating REST Facts from Fallacies
 
The RESTful Soa Datagrid with Oracle
The RESTful Soa Datagrid with OracleThe RESTful Soa Datagrid with Oracle
The RESTful Soa Datagrid with Oracle
 
Helping Things to REST
Helping Things to RESTHelping Things to REST
Helping Things to REST
 
Unit 2
Unit 2Unit 2
Unit 2
 
RESTing with JAX-RS
RESTing with JAX-RSRESTing with JAX-RS
RESTing with JAX-RS
 
RESTful services
RESTful servicesRESTful services
RESTful services
 
REST Basics
REST BasicsREST Basics
REST Basics
 
Дмитрий Красун: Сегодня вы уйдете с новым представлением о REST
Дмитрий Красун: Сегодня вы уйдете с новым представлением о RESTДмитрий Красун: Сегодня вы уйдете с новым представлением о REST
Дмитрий Красун: Сегодня вы уйдете с новым представлением о REST
 
Rest with Spring
Rest with SpringRest with Spring
Rest with Spring
 
Network Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyNetwork Device Database Management with REST using Jersey
Network Device Database Management with REST using Jersey
 
Restful web services rule financial
Restful web services   rule financialRestful web services   rule financial
Restful web services rule financial
 
The Glory of Rest
The Glory of RestThe Glory of Rest
The Glory of Rest
 

PyCon 2010 REST Talk

  • 1. PyCon 2010, Atlanta Creating RESTful Web Services with restish Grig Gheorghiu Evite grig.gheorghiu@evite.com    
  • 2. Credits  Roy Fielding Ph.D. Dissertation  'RESTful Web Services' book by L. Richardson  and S. Ruby (O'Reilly)  Joe Gregorio's REST articles for xml.com  Mark Pilgrim's Web services tutorial in 'Dive into  Python'  Mark Nottingham's Web caching tutorials    
  • 3. What is a web service?  Specific kind of Web application  Consumed by applications, not directly by  humans/browsers  Typically emits XML or JSON and not HTML  Examples: Amazon Web Services (S3, SQS,  EC2), Yahoo Web Services (del.icio.us, Flickr)  'Programmable Web':  http://www.programmableweb.com/apis/directory/    
  • 4. What is REST?  ”REpresentational StateTransfer”: Roy Fielding,  Ph.D. Dissertation, UC Irvine, 2000  'Architectural style for distributed hypermedia  systems'; start with NULL style and add  constraints:  Client­Server  Stateless  Cache  Uniform Interface    Layered System  
  • 5. HTTP crash course  Requests and responses  HTTP request: a method (GET, POST, PUT,  DELETE, HEAD), a path (/index.html), a set of  headers, and the entity­body (representation)  HTTP response: a response code (200, 404,  etc.), a set of headers, and the entity­body  (representation)  Lingua franca of the Internet    
  • 6. Web architectures  REST(ful)  Based on HTTP methods (GET, POST, PUT, DELETE)  Arguments to methods go in URIs or in HTTP payloads  Amazon S3, last.fm API  RPC­style (SOAP, XML­RPC)  Typically one single URI is exposed  Heavy on POST operations  Hybrid REST­RPC  Overloaded GET used to modify data    Bad idea (remember Google Web Accelerator?)  
  • 7. Resource­Oriented Architecture  Leonard Richardson and Sam Ruby  4 concepts: resources, their names, their  representations, the links between them  4 properties: addressability, statelessnes,  connectedness, uniform interface    
  • 8. Resources and URIs  Resource == anything that is important enough  to be referenced (or linked to)  Comparable to objects in OO design  Every resource has a 'name': URI == Uniform  Resource Identifier  1 resource → N URIs  Examples of URIs:  URL(ocator): http://socal­piggies.org/scp  URN(ame): urn:isbn:0­395­36341­1    
  • 9. Representations and links  Representation == concrete data which  describes the current state of a resource  Example: description of the most recent bug  In practice: a specific data format (XML, JSON,  etc)  Client­server state transfer happens by  exchange of representations (hence  ”REpresentational State Transfer”)  Server guides client from one state to another    by means of links embedded in representations  
  • 10. Addressability  Resources exposed as URIs are addressable  Can be linked to  Can be bookmarked  Can be printed in a book  Can be sent in an email  Can be cached  Openness vs. Opacity; REST vs. RPC  Think 'mashups'!    
  • 11. Statelessness  Each HTTP request contains all the state it  needs for the server to fulfil it  State is only on the client side!  Server can nudge client to different states via  links (connectedness)  Statelessness induces:  Visibility: each request can be monitored in isolation  Reliability: easier to recover from partial failures  Scalability: easy to scale horizontally    
  • 12. The Uniform Interface  Methods dictated by HTTP verbs (uniformity) uniformity  CRUD operations  Create: POST/PUT  Retrieve: GET (HEAD for resource metadata)  Update: PUT  Delete: DELETE  GET and HEAD should be safe (no changes to  server state)  GET, HEAD, PUT should be idempotent    
  • 13. So...why REST?  Client­Server (Web client ↔ Web server)  Stateless (client keeps state)  Uniform interface (HTTP methods)  Caching  Reduces latency  Reduces network bandwidth  Layered system (higher application layer calls  lower Web services layer)    
  • 14. HTTP caching in a nutshell  Special HTTP headers  Server: freshness indicators (”it's safe to  cache”)  Cache­control → absolute date/time  Expires → delta relative to time of request  Server: validators (”is it still safe to cache?”)  Last­Modified → absolute date/time  Etag → hash of content  Client: If­Modified­Since (for Last­Modified)   Client: If­None­Match (for Etag)  
  • 15. Creating a RESTful service  Joe Gregorio article ”How to create a REST  protocol”  To create a REST service, you need to answer  the following questions, and you should answer  them in this order:  What are the URIs? (resources)  What's the format? (representations)  What methods are supported at each URI?  What status codes could be returned?    
  • 16. Introducing the restish framework  Created by Tim Parkin and Matt Goodall  Part of the 'ish' family of tools at http://github.com/ish  Formish  Adminish  Couchish  Example site developed with restish:  www.profiled.com    
  • 17. Why restish?  Close­to­the­metal, REST­oriented, WSGI  aware  Well tested and powerful URL handling, parsing  and creation  Powerful but simple HTTP request and  response handling (based on WebOb)  Simple integration with templating frameworks  (mako, jinja2, genshi, django)  Basic HTTP auth via guard module (e.g. using    repoze.who as WSGI middleware)  
  • 18. Demo app: todoish list mgmt  What are the URIs? (resources)  /lists/LISTID/items/ITEMID  What's the format? (representations)  JSON  What methods are supported at each URI?  POST, PUT, GET  What status codes could be returned?  Success: 200 OK, 201 Created  Error: 404 Not Found, 501 Not Implemented    
  • 19. Consuming Web services  Curl curl -i -X POST 127.0.0.1:9999/lists/ -H "Content- Type: application/json" -d '{"name":"new list"}'  Httplib2    
  • 20. Testing a restish Web app  Unit testing: WebTest  Functional testing: twill (for HTML  representations)    
  • 21. Deploying a restish Web app  Run web application process properly as a  daemon (e.g. using grizzled.os)  Use log rotation (rotatelogs, scribe)  Use automated deployment tools (fabric)  Use robust reverse proxy/load balancer (e.g.  nginx)    
  • 22. What should you take away?  blah blah blah RESOURCES blah blah blah  HTTP UNIFORM INTERFACE blah blah  STATELESSNESS blah blah JSON/XML blah  blah RESTISH blah blah TESTING blah blah  AUTOMATED DEPLOYMENTS blah blah  EVITE IS HIRING PYTHON PROGRAMMERS