SlideShare a Scribd company logo
1 of 40
Download to read offline
     
Representational State
                 Transfer




             
RESTful Principles




              
A universal syntax for
    resource-identification




                
A set of well-defined
         operations




               
Having a shared set of
         media-types




                
The use of hypermedia for
application state-transitions


               
Stateless
        protocol




     
Building a
RESTful
App




              
RESTfully Delicious
    ●
        Get a list of all bookmarks
        ●
            filter by user and/or tag
        ●
            limit by number
    ●
        Add a bookmark
    ●
        Edit a bookmark
    ●
        Delete a bookmark


                                         
Discover Resources
Resources          URLs                Methods Representations
Bookmark           /bookmarks/{md5} GET          application/bookmark+xml
                                       PUT    application/bookmark+xml
                                       DELETE
Bookmark list      /bookmarks          GET       application/atom+xml
Resources          URLs                Methods   Representations
                                       POST      application/bookmark+xml
User list          /users              GET       application/atom+xml
Users bookmarks    /users/{user}       GET       application/atom+xml
Tag list           /tags               GET       application/atom+xml
Tagged bookmarks   /tags/{tag}         GET       application/atom+xml
Homepage           /                   GET       application/delicious+xml




                                    
GETting the Homepage
    GET /
    200 OK
    Content­type: application/delicious+xml
    <?xml version=”1.0”?>
    <delicious users=”/users” bookmarks=”/bookmarks” tags=”/tags”>
       <recent start=”1” end=”20” next=”/?start=21&amp;end=40”>
             <bookmark url=quot;http://www.example.org/something­
               interstingquot; 
               href=quot;/bookmarks/a211528fb5108cddaa4b0d3aeccdbdcfquot;/>
             ...
       </recent>
    </delicious>



                                       
GETting Bookmarks
    GET /bookmarks
    200 OK
    Content­type: application/atom+xml
    <?xml version=quot;1.0quot;?>
    <feed xmlns=quot;http://www.w3.org/2005/Atomquot;>
      <title>Bookmarks</title>
      <entry>
        <title>Something interesting</title>
        <link href=quot;/bookmarks/a211528fb5108cddaa4b0d3aeccdbdcfquot;/>
        <summary>http://example.org/something­intersting</summary>
      </entry>
    </feed>
                                     
GETting A Bookmark
    GET /bookmarks/a211528fb5108cddaa4b0d3aeccdbdcf
    200 OK
    Content­type: application/bookmark+xml
    <?xml version=quot;1.0quot;?>
    <bookmark>
      <title>Something interesting</title>
      <url>http://example.org/something­intersting</url>
      <user href=”/users/pauljames”>pauljames</user>
      <tags>
        <tag href=”/tags/interesting”>interesting</tag>
      </tags>
    </bookmark>
                                     
Creating and Updating
    POST /bookmarks
    Content­type: application/bookmark+xml
    ...
    201 Created
    Location: /bookmarks/a211528fb5108cddaa4b0d3aeccdbdcf



    PUT /bookmarks/a211528fb5108cddaa4b0d3aeccdbdcf
    Content­type: application/bookmark+xml
    ...
    200 OK



                                     
Benefits of Being RESTful
    ●
        Better scaling due to stateless communications 
    ●
        Better response times due to caching
    ●
        Better long­term compatibility due to:
        ●
            the capability of document types to evolve without 
            breaking backwards­compatibility
        ●
            the ability to add support for new content types 
            without reducing support for older content types.
    ●
        Do less with more
                                    
Finally, some PHP
HTTP method
    $_SERVER['REQUEST_METHOD']

Reading request data
    $_SERVER['CONTENT_LENGTH']
    $_SERVER['CONTENT_TYPE']
    POST - $HTTP_RAW_POST_DATA

    Other HTTP methods   -   fopen('php://input', 'r')

Processing request data
    SimpleXML, MiniXML, PHP JSON, parse_str, unserialize,
     unpack, preg_match, etc.
                                 
Generating Responses
HTTP response codes
    200 OK, 201 Created, 204 No Content, 304 Not
     Modified, 401 Unauthorized, 404 Not Found, 405
     Method Not Allowed, 411 Length Required, 415
     Unsupported Media Type
Generating representations
    Smarty, PHPFastTemplate, GD, SimpleXML, printf, etc.
HTTP caching
    Expires, Cache-Control, Etag, Last-Modified
    header('Expires: '.gmdate('D, j M Y H:i:s T', time() + 
      $cachelength));
    header('Cache­Control: max­age='.$cachelength.', must­
      revalidate');
                                   
Conclusion
    ●
        REST is not just about “Web Services”
    ●
        Set of best practices for building Web apps
        ●
            Give everything a URL
        ●
            Use correct HTTP methods
        ●
            Use common media types
        ●
            Link things together with hypertext



                                     
Further Reading
    ●
        Roger L. Costello (http://www.xfront.com/REST­
        Web­Services.html)
    ●
        Paul Prescod (http://www.prescod.net/rest/)
    ●
        REST Wiki (http://rest.blueoxen.net/)
    ●
        Atom Publishing Protocol 
        (http://atomenabled.org/developers/protocol/)
    ●
        http://del.icio.us/tag/rest
                                  
                                                         




                                  
                                                    1



     Introduction
     Questions

     Overloaded term

     POX over HTTP?
     Other HTTP methods?
     Tidy URLs?
     Buzzword?

    http://flickr.com/photos/estherase/128983854/




 
                                                                    




                  Representational State
                               Transfer




                                   
                                                         2



    Architectural style
    Distilled from the Web by Roy Fielding
    HTTP 1.1 was designed to conform to REST
    Defines how the Web works
    Describes a set of rules for building applications on the 
       Web that exhibit certain desirable properties
    REST is not HTTP, but HTTP is RESTful

    “it’s the way the Web already works, just formalized a bit  
         and with some do’s and don’ts.”

    Web service is a Web page that’s meant to be consumed 
      by an autonomous program as opposed to a Web 
      browser

    http://flickr.com/photos/practicalowl/392894653/
 
                                                                    




                    RESTful Principles




                                   
                                                        3



     5 principles

     ●
         A universal syntax for resource­identification ­ URLs
     ●
         A set of well­defined operations
     ●
         Having a shared set of media­types
     ●
         The use of hypermedia for application state­transitions
     ●
         Stateless protocol – all state on the client

    http://flickr.com/photos/thowi/113223967/




 
                                                                      




               A universal syntax for
               resource-identification




                                     
                                                           4



     ●
         Uniform resource locators (URLs)
     ●
         Every resource (thing of interest) has a URL
     ●
         URLs are unique and allow us to dereference a 
         resource
     ●
         Nouns
     ●
         Trillions of nouns for all the concepts in all the heads 
         and files of all the people in the world

    http://flickr.com/photos/joeholmes/258136938/




 
                                                                  




                 A set of well-defined
                      operations




                                   
                                                        5



     ●
         HTTP methods ­ verbs
     ●
         GET – fetch
     ●
         POST ­ append/process
     ●
         PUT ­ create/update
     ●
         DELETE ­ delete
     ●
         Uniform interface, GET always gets, PUT always 
         creates
     ●
         Using different verbs for different nouns would make 
         widespread communication impossible
     ●
         There are no applications you can think of which 
         cannot be made to fit

    http://flickr.com/photos/joygant/971783023/




 
                                                                  




               Having a shared set of
                    media-types




                                  
                                                       6



     ●
         What's not machine­processable about the current 
         Web isn't the protocol, it's the content
     ●
         Information conveyed via documents
     ●
         A standard set of document formats (HTML, RDF, 
         JPEG, PNG, etc.)
     ●
         Representation of a resource
     ●
         Resources are just concepts, representations are how 
         we interact with them

    http://flickr.com/photos/thefrankfurtschool/1305454450/




 
                                                                     




             The use of hypermedia for
           application state-transitions


                                   
                                                        7



     ●
         Hypertext provides links between resources
     ●
         Clients change state (navigate the Web) via information 
         from a previous state
     ●
         URLs are opaque to clients, they never construct URLs
     ●
         Because the links mirror the structure of how a user 
         makes progress through an application
     ●
         A Web­based application is a dynamically changing 
         graph of state representations (pages) and potential 
         transitions (links) between states
     ●
         If not, it may be accessible from the Web, but it’s not 
         really part of the Web


    http://flickr.com/photos/pgoyette/100769956/



 
                                                                     




                                           Stateless
                                           protocol




                                     
                                                         8



    ●
        Application state is the information necessary to 
        understand the context of an interaction – auth details, 
        etc.
    ●
        Resource state – S in REST, avoid unnamed state
    ●
        All requests must include all application state
    ●
        Session state is application state – if you want  a 
        session you need a smarter client than a browser – 
        shopping cart

    ●
        Prevents partial failures
    ●
        Load­balancing
    ●
        Service interruptions

    http://flickr.com/photos/davenyc/23033147/


 
                                                       




           Building a
           RESTful
           App




                               
                                                  9



    ●
        Discover first class objects
    ●
        Our resources
    ●
        Assign URLs and URL­spaces
    ●
        Define representations
    ●
        Input and output formats
    ●
        Define HTTP methods

    Time for an Example

    http://flickr.com/photos/hugovk/2037935886/




 
                                                             




          RESTfully Delicious
               ●
                   Get a list of all bookmarks
                   ●
                       filter by user and/or tag
                   ●
                       limit by number
               ●
                   Add a bookmark
               ●
                   Edit a bookmark
               ●
                   Delete a bookmark


                                                    
                                                       10



     Get a list of all bookmarks
           filter by user and/or tag
           limit by number
     Add a bookmark
     Edit a bookmark
     Delete a bookmark

    http://flickr.com/photos/sharynmorrow/124428600/




 
                                                                                       




         Discover Resources
         Resources          URLs                Methods Representations
         Bookmark           /bookmarks/{md5} GET          application/bookmark+xml
                                                PUT    application/bookmark+xml
                                                DELETE
         Bookmark list      /bookmarks          GET       application/atom+xml
         Resources          URLs                Methods   Representations
                                                POST      application/bookmark+xml
         User list          /users              GET       application/atom+xml
         Users bookmarks    /users/{user}       GET       application/atom+xml
         Tag list           /tags               GET       application/atom+xml
         Tagged bookmarks   /tags/{tag}         GET       application/atom+xml
         Homepage           /                   GET       application/delicious+xml




                                             
                                                                                11




    http://flickr.com/photos/sharynmorrow/124428600/




 
                                                                                     




         GETting the Homepage
             GET /
             200 OK
             Content­type: application/delicious+xml
             <?xml version=”1.0”?>
             <delicious users=”/users” bookmarks=”/bookmarks” tags=”/tags”>
                <recent start=”1” end=”20” next=”/?start=21&amp;end=40”>
                      <bookmark url=quot;http://www.example.org/something­
                        interstingquot; 
                        href=quot;/bookmarks/a211528fb5108cddaa4b0d3aeccdbdcfquot;/>
                      ...
                </recent>
             </delicious>



                                                
                                                                               12




    http://flickr.com/photos/sharynmorrow/124428600/




 
                                                                                    




         GETting Bookmarks
             GET /bookmarks
             200 OK
             Content­type: application/atom+xml
             <?xml version=quot;1.0quot;?>
             <feed xmlns=quot;http://www.w3.org/2005/Atomquot;>
               <title>Bookmarks</title>
               <entry>
                 <title>Something interesting</title>
                 <link href=quot;/bookmarks/a211528fb5108cddaa4b0d3aeccdbdcfquot;/>
                 <summary>http://example.org/something­intersting</summary>
               </entry>
             </feed>
                                              
                                                                              13




    http://flickr.com/photos/sharynmorrow/124428600/




 
                                                                          




         GETting A Bookmark
             GET /bookmarks/a211528fb5108cddaa4b0d3aeccdbdcf
             200 OK
             Content­type: application/bookmark+xml
             <?xml version=quot;1.0quot;?>
             <bookmark>
               <title>Something interesting</title>
               <url>http://example.org/something­intersting</url>
               <user href=”/users/pauljames”>pauljames</user>
               <tags>
                 <tag href=”/tags/interesting”>interesting</tag>
               </tags>
             </bookmark>
                                              
                                                                    14




    http://flickr.com/photos/sharynmorrow/124428600/




 
                                                                           




         Creating and Updating
             POST /bookmarks
             Content­type: application/bookmark+xml
             ...
             201 Created
             Location: /bookmarks/a211528fb5108cddaa4b0d3aeccdbdcf



             PUT /bookmarks/a211528fb5108cddaa4b0d3aeccdbdcf
             Content­type: application/bookmark+xml
             ...
             200 OK



                                              
                                                                     15




    http://flickr.com/photos/sharynmorrow/124428600/




 
                                                                               




         Benefits of Being RESTful
             ●
                 Better scaling due to stateless communications 
             ●
                 Better response times due to caching
             ●
                 Better long­term compatibility due to:
                 ●
                     the capability of document types to evolve without 
                     breaking backwards­compatibility
                 ●
                     the ability to add support for new content types 
                     without reducing support for older content types.
             ●
                 Do less with more
                                             
                                                                         16




    Better scaling due to stateless communications 
    Better response times due to caching
    Better long­term compatibility due to:
        the capability of document types to evolve 
           without breaking backwards­compatibility
        the ability to add support for new content types 
           without reducing support for older content 
           types.
    Lower learning curve for consumer
    Lower support overhead for producer

    http://flickr.com/photos/ari/1387533615/



 
                                                                           




             Finally, some PHP
         HTTP method
             $_SERVER['REQUEST_METHOD']

         Reading request data
             $_SERVER['CONTENT_LENGTH']
             $_SERVER['CONTENT_TYPE']
             POST - $HTTP_RAW_POST_DATA

             Other HTTP methods   -   fopen('php://input', 'r')

         Processing request data
             SimpleXML, MiniXML, PHP JSON, parse_str, unserialize,
              unpack, preg_match, etc.
                                          
                                                                     17




    http://flickr.com/photos/nez/378348754/




 
                                                                             




             Generating Responses
         HTTP response codes
             200 OK, 201 Created, 204 No Content, 304 Not
              Modified, 401 Unauthorized, 404 Not Found, 405
              Method Not Allowed, 411 Length Required, 415
              Unsupported Media Type
         Generating representations
             Smarty, PHPFastTemplate, GD, SimpleXML, printf, etc.
         HTTP caching
             Expires, Cache-Control, Etag, Last-Modified
             header('Expires: '.gmdate('D, j M Y H:i:s T', time() + 
               $cachelength));
             header('Cache­Control: max­age='.$cachelength.', must­
               revalidate');
                                            
                                                                       18




    http://flickr.com/photos/nez/378348754/




 
                                                                    




        Conclusion
            ●
                REST is not just about “Web Services”
            ●
                Set of best practices for building Web apps
                ●
                    Give everything a URL
                ●
                    Use correct HTTP methods
                ●
                    Use common media types
                ●
                    Link things together with hypertext



                                             
                                                              19




    REST is not just about “Web Services”
    Set of best practices for building Web apps
        Give everything a URL
        Use correct HTTP methods
        Use common media types
        Link things together with hypertext

    REST is an architectural style
    It defines 4 core principles
      A universal syntax for resource-
        identification
      A set of well-defined operations
      Having a shared set of media-types
      The use of hypermedia for application
        state-transitions
      Stateless client/server interaction
    It helps us write well behaved apps
                                                                       




         Further Reading
             ●
                 Roger L. Costello (http://www.xfront.com/REST­
                 Web­Services.html)
             ●
                 Paul Prescod (http://www.prescod.net/rest/)
             ●
                 REST Wiki (http://rest.blueoxen.net/)
             ●
                 Atom Publishing Protocol 
                 (http://atomenabled.org/developers/protocol/)
             ●
                 http://del.icio.us/tag/rest
                                           
                                                                 20




    http://flickr.com/photos/dhammza/91435718/




 

More Related Content

What's hot

How I learned to stop worrying and love the .htaccess file
How I learned to stop worrying and love the .htaccess fileHow I learned to stop worrying and love the .htaccess file
How I learned to stop worrying and love the .htaccess fileRoxana Stingu
 
Optaros Surf Code Camp Dispatcher
Optaros Surf Code Camp DispatcherOptaros Surf Code Camp Dispatcher
Optaros Surf Code Camp DispatcherJeff Potts
 
Drawing the Line with Browser Compatibility
Drawing the Line with Browser CompatibilityDrawing the Line with Browser Compatibility
Drawing the Line with Browser Compatibilityjsmith92
 
Optaros Surf Code Camp Lab 2
Optaros Surf Code Camp Lab 2Optaros Surf Code Camp Lab 2
Optaros Surf Code Camp Lab 2Jeff Potts
 
Optaros Surf Code Camp Lab 3
Optaros Surf Code Camp Lab 3Optaros Surf Code Camp Lab 3
Optaros Surf Code Camp Lab 3Jeff Potts
 
Fundamentals of web_design_v2
Fundamentals of web_design_v2Fundamentals of web_design_v2
Fundamentals of web_design_v2hussain534
 
Doctype html
Doctype htmlDoctype html
Doctype htmlEddy_TKJ
 
CC tech-projects: overview (TELDAP 2009)
CC tech-projects: overview (TELDAP 2009)CC tech-projects: overview (TELDAP 2009)
CC tech-projects: overview (TELDAP 2009)Bob Chao
 
Optaros Surf Code Camp Lab 4
Optaros Surf Code Camp Lab 4Optaros Surf Code Camp Lab 4
Optaros Surf Code Camp Lab 4Jeff Potts
 
LESS is More
LESS is MoreLESS is More
LESS is Morejsmith92
 
Optaros Surf Code Camp Introduction
Optaros Surf Code Camp IntroductionOptaros Surf Code Camp Introduction
Optaros Surf Code Camp IntroductionJeff Potts
 
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS W...
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS W...More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS W...
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS W...Shift Conference
 
S314011 - Developing Composite Applications for the Cloud with Apache Tuscany
S314011 - Developing Composite Applications for the Cloud with Apache TuscanyS314011 - Developing Composite Applications for the Cloud with Apache Tuscany
S314011 - Developing Composite Applications for the Cloud with Apache TuscanyLuciano Resende
 
Changhao jiang facebook
Changhao jiang facebookChanghao jiang facebook
Changhao jiang facebookzipeng zhang
 
HTML5 is the Future of Mobile, PhoneGap Takes You There Today
HTML5 is the Future of Mobile, PhoneGap Takes You There TodayHTML5 is the Future of Mobile, PhoneGap Takes You There Today
HTML5 is the Future of Mobile, PhoneGap Takes You There Todaydavyjones
 
BOSS Open Hack Day, Bangalore
BOSS Open Hack Day, BangaloreBOSS Open Hack Day, Bangalore
BOSS Open Hack Day, BangaloreSaurabh Sahni
 
Web Feeds and Repositories
Web Feeds and RepositoriesWeb Feeds and Repositories
Web Feeds and RepositoriesJim Downing
 
Getting Started with HTML5 in Tech Com (STC 2012)
Getting Started with HTML5 in Tech Com (STC 2012)Getting Started with HTML5 in Tech Com (STC 2012)
Getting Started with HTML5 in Tech Com (STC 2012)Peter Lubbers
 
Yahoo Communities Architecture Unlikely Bedfellows
Yahoo Communities Architecture Unlikely BedfellowsYahoo Communities Architecture Unlikely Bedfellows
Yahoo Communities Architecture Unlikely BedfellowsConSanFrancisco123
 

What's hot (20)

How I learned to stop worrying and love the .htaccess file
How I learned to stop worrying and love the .htaccess fileHow I learned to stop worrying and love the .htaccess file
How I learned to stop worrying and love the .htaccess file
 
Optaros Surf Code Camp Dispatcher
Optaros Surf Code Camp DispatcherOptaros Surf Code Camp Dispatcher
Optaros Surf Code Camp Dispatcher
 
Drawing the Line with Browser Compatibility
Drawing the Line with Browser CompatibilityDrawing the Line with Browser Compatibility
Drawing the Line with Browser Compatibility
 
Optaros Surf Code Camp Lab 2
Optaros Surf Code Camp Lab 2Optaros Surf Code Camp Lab 2
Optaros Surf Code Camp Lab 2
 
Optaros Surf Code Camp Lab 3
Optaros Surf Code Camp Lab 3Optaros Surf Code Camp Lab 3
Optaros Surf Code Camp Lab 3
 
Fundamentals of web_design_v2
Fundamentals of web_design_v2Fundamentals of web_design_v2
Fundamentals of web_design_v2
 
Doctype html
Doctype htmlDoctype html
Doctype html
 
CC tech-projects: overview (TELDAP 2009)
CC tech-projects: overview (TELDAP 2009)CC tech-projects: overview (TELDAP 2009)
CC tech-projects: overview (TELDAP 2009)
 
Optaros Surf Code Camp Lab 4
Optaros Surf Code Camp Lab 4Optaros Surf Code Camp Lab 4
Optaros Surf Code Camp Lab 4
 
LESS is More
LESS is MoreLESS is More
LESS is More
 
Optaros Surf Code Camp Introduction
Optaros Surf Code Camp IntroductionOptaros Surf Code Camp Introduction
Optaros Surf Code Camp Introduction
 
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS W...
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS W...More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS W...
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS W...
 
S314011 - Developing Composite Applications for the Cloud with Apache Tuscany
S314011 - Developing Composite Applications for the Cloud with Apache TuscanyS314011 - Developing Composite Applications for the Cloud with Apache Tuscany
S314011 - Developing Composite Applications for the Cloud with Apache Tuscany
 
Changhao jiang facebook
Changhao jiang facebookChanghao jiang facebook
Changhao jiang facebook
 
HTML5 is the Future of Mobile, PhoneGap Takes You There Today
HTML5 is the Future of Mobile, PhoneGap Takes You There TodayHTML5 is the Future of Mobile, PhoneGap Takes You There Today
HTML5 is the Future of Mobile, PhoneGap Takes You There Today
 
Echo HTML5
Echo HTML5Echo HTML5
Echo HTML5
 
BOSS Open Hack Day, Bangalore
BOSS Open Hack Day, BangaloreBOSS Open Hack Day, Bangalore
BOSS Open Hack Day, Bangalore
 
Web Feeds and Repositories
Web Feeds and RepositoriesWeb Feeds and Repositories
Web Feeds and Repositories
 
Getting Started with HTML5 in Tech Com (STC 2012)
Getting Started with HTML5 in Tech Com (STC 2012)Getting Started with HTML5 in Tech Com (STC 2012)
Getting Started with HTML5 in Tech Com (STC 2012)
 
Yahoo Communities Architecture Unlikely Bedfellows
Yahoo Communities Architecture Unlikely BedfellowsYahoo Communities Architecture Unlikely Bedfellows
Yahoo Communities Architecture Unlikely Bedfellows
 

Viewers also liked

Exploratory Statistics with R
Exploratory Statistics with RExploratory Statistics with R
Exploratory Statistics with RChristian Robert
 
Configuring Apache Web Server For Single Sign-On with Likewise
Configuring Apache Web Server For Single Sign-On with LikewiseConfiguring Apache Web Server For Single Sign-On with Likewise
Configuring Apache Web Server For Single Sign-On with Likewisewebhostingguy
 
Theory of Probability revisited
Theory of Probability revisitedTheory of Probability revisited
Theory of Probability revisitedChristian Robert
 
Easy rest service using PHP reflection api
Easy rest service using PHP reflection apiEasy rest service using PHP reflection api
Easy rest service using PHP reflection apiMatthieu Aubry
 
Apache web server
Apache web serverApache web server
Apache web serverzrstoppe
 
Apache Server Tutorial
Apache Server TutorialApache Server Tutorial
Apache Server TutorialJagat Kothari
 
8 wcdma rf optimization&case study-60
8 wcdma rf optimization&case study-608 wcdma rf optimization&case study-60
8 wcdma rf optimization&case study-60Ba Quynh Nguyen
 
Apache Web server Complete Guide
Apache Web server Complete GuideApache Web server Complete Guide
Apache Web server Complete Guidewebhostingguy
 
01 principles of the wcdma system
01 principles of the wcdma system01 principles of the wcdma system
01 principles of the wcdma systemkhurrambilal01
 

Viewers also liked (15)

Apache
Apache Apache
Apache
 
Exploratory Statistics with R
Exploratory Statistics with RExploratory Statistics with R
Exploratory Statistics with R
 
Practical REST API
Practical REST APIPractical REST API
Practical REST API
 
Wcdma planning
Wcdma planningWcdma planning
Wcdma planning
 
Configuring Apache Web Server For Single Sign-On with Likewise
Configuring Apache Web Server For Single Sign-On with LikewiseConfiguring Apache Web Server For Single Sign-On with Likewise
Configuring Apache Web Server For Single Sign-On with Likewise
 
Theory of Probability revisited
Theory of Probability revisitedTheory of Probability revisited
Theory of Probability revisited
 
Easy rest service using PHP reflection api
Easy rest service using PHP reflection apiEasy rest service using PHP reflection api
Easy rest service using PHP reflection api
 
Apache ppt
Apache pptApache ppt
Apache ppt
 
Apache web server
Apache web serverApache web server
Apache web server
 
Apache Server Tutorial
Apache Server TutorialApache Server Tutorial
Apache Server Tutorial
 
8 wcdma rf optimization&case study-60
8 wcdma rf optimization&case study-608 wcdma rf optimization&case study-60
8 wcdma rf optimization&case study-60
 
Apache Web server Complete Guide
Apache Web server Complete GuideApache Web server Complete Guide
Apache Web server Complete Guide
 
3G basic good
3G basic good3G basic good
3G basic good
 
01 principles of the wcdma system
01 principles of the wcdma system01 principles of the wcdma system
01 principles of the wcdma system
 
Web Servers (ppt)
Web Servers (ppt)Web Servers (ppt)
Web Servers (ppt)
 

Similar to RESTful Principles and Best Practices

Restful webservice
Restful webserviceRestful webservice
Restful webserviceDong Ngoc
 
Resource-Oriented Web Services
Resource-Oriented Web ServicesResource-Oriented Web Services
Resource-Oriented Web ServicesBradley Holt
 
HTTP colon slash slash: the end of the road?
HTTP colon slash slash: the end of the road?HTTP colon slash slash: the end of the road?
HTTP colon slash slash: the end of the road?Alessandro Nadalin
 
Applications of the REST Principle
Applications of the REST PrincipleApplications of the REST Principle
Applications of the REST Principleelliando dias
 
The Case for HTTP/2
The Case for HTTP/2The Case for HTTP/2
The Case for HTTP/2Andy Davies
 
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...ruyalarcon
 
An Overview on PROV-AQ: Provenance Access and Query
An Overview on PROV-AQ: Provenance Access and QueryAn Overview on PROV-AQ: Provenance Access and Query
An Overview on PROV-AQ: Provenance Access and QueryOlaf Hartig
 
Moving from Web 1.0 to Web 2.0
Moving from Web 1.0 to Web 2.0Moving from Web 1.0 to Web 2.0
Moving from Web 1.0 to Web 2.0Estelle Weyl
 
Great APIs - Future of Your Progress App
Great APIs - Future of Your Progress AppGreat APIs - Future of Your Progress App
Great APIs - Future of Your Progress AppGabriel Lucaciu
 
REST in ( a mobile ) peace @ WHYMCA 05-21-2011
REST in ( a mobile ) peace @ WHYMCA 05-21-2011REST in ( a mobile ) peace @ WHYMCA 05-21-2011
REST in ( a mobile ) peace @ WHYMCA 05-21-2011Alessandro Nadalin
 
Grokking REST (ZendCon 2010)
Grokking REST (ZendCon 2010)Grokking REST (ZendCon 2010)
Grokking REST (ZendCon 2010)Ben Ramsey
 
Standardizing the Web: A Look into the Why of Web Standards
Standardizing the Web: A Look into the Why of Web StandardsStandardizing the Web: A Look into the Why of Web Standards
Standardizing the Web: A Look into the Why of Web StandardsTim Wright
 
ReST Vs SOA(P) ... Yawn
ReST Vs SOA(P) ... YawnReST Vs SOA(P) ... Yawn
ReST Vs SOA(P) ... Yawnozten
 
KMUTNB - Internet Programming 2/7
KMUTNB - Internet Programming 2/7KMUTNB - Internet Programming 2/7
KMUTNB - Internet Programming 2/7phuphax
 

Similar to RESTful Principles and Best Practices (20)

Markup As An Api
Markup As An ApiMarkup As An Api
Markup As An Api
 
Restful webservice
Restful webserviceRestful webservice
Restful webservice
 
Resource-Oriented Web Services
Resource-Oriented Web ServicesResource-Oriented Web Services
Resource-Oriented Web Services
 
HTTP colon slash slash: the end of the road?
HTTP colon slash slash: the end of the road?HTTP colon slash slash: the end of the road?
HTTP colon slash slash: the end of the road?
 
SearchMonkey
SearchMonkeySearchMonkey
SearchMonkey
 
Applications of the REST Principle
Applications of the REST PrincipleApplications of the REST Principle
Applications of the REST Principle
 
The Case for HTTP/2
The Case for HTTP/2The Case for HTTP/2
The Case for HTTP/2
 
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
 
Sword v2 at UKCoRR
Sword v2 at UKCoRRSword v2 at UKCoRR
Sword v2 at UKCoRR
 
An Overview on PROV-AQ: Provenance Access and Query
An Overview on PROV-AQ: Provenance Access and QueryAn Overview on PROV-AQ: Provenance Access and Query
An Overview on PROV-AQ: Provenance Access and Query
 
Web Services
Web ServicesWeb Services
Web Services
 
Moving from Web 1.0 to Web 2.0
Moving from Web 1.0 to Web 2.0Moving from Web 1.0 to Web 2.0
Moving from Web 1.0 to Web 2.0
 
Great APIs - Future of Your Progress App
Great APIs - Future of Your Progress AppGreat APIs - Future of Your Progress App
Great APIs - Future of Your Progress App
 
REST in ( a mobile ) peace @ WHYMCA 05-21-2011
REST in ( a mobile ) peace @ WHYMCA 05-21-2011REST in ( a mobile ) peace @ WHYMCA 05-21-2011
REST in ( a mobile ) peace @ WHYMCA 05-21-2011
 
Grokking REST (ZendCon 2010)
Grokking REST (ZendCon 2010)Grokking REST (ZendCon 2010)
Grokking REST (ZendCon 2010)
 
Standardizing the Web: A Look into the Why of Web Standards
Standardizing the Web: A Look into the Why of Web StandardsStandardizing the Web: A Look into the Why of Web Standards
Standardizing the Web: A Look into the Why of Web Standards
 
Boost and SEO
Boost and SEOBoost and SEO
Boost and SEO
 
Rest Vs Soap Yawn2289
Rest Vs Soap Yawn2289Rest Vs Soap Yawn2289
Rest Vs Soap Yawn2289
 
ReST Vs SOA(P) ... Yawn
ReST Vs SOA(P) ... YawnReST Vs SOA(P) ... Yawn
ReST Vs SOA(P) ... Yawn
 
KMUTNB - Internet Programming 2/7
KMUTNB - Internet Programming 2/7KMUTNB - Internet Programming 2/7
KMUTNB - Internet Programming 2/7
 

Recently uploaded

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 

Recently uploaded (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 

RESTful Principles and Best Practices

  • 1.    
  • 2. Representational State Transfer    
  • 4. A universal syntax for resource-identification    
  • 5. A set of well-defined operations    
  • 6. Having a shared set of media-types    
  • 7. The use of hypermedia for application state-transitions    
  • 8. Stateless protocol    
  • 10. RESTfully Delicious ● Get a list of all bookmarks ● filter by user and/or tag ● limit by number ● Add a bookmark ● Edit a bookmark ● Delete a bookmark    
  • 11. Discover Resources Resources URLs Methods Representations Bookmark /bookmarks/{md5} GET application/bookmark+xml PUT application/bookmark+xml DELETE Bookmark list /bookmarks GET application/atom+xml Resources URLs Methods Representations POST application/bookmark+xml User list /users GET application/atom+xml Users bookmarks /users/{user} GET application/atom+xml Tag list /tags GET application/atom+xml Tagged bookmarks /tags/{tag} GET application/atom+xml Homepage / GET application/delicious+xml    
  • 12. GETting the Homepage GET / 200 OK Content­type: application/delicious+xml <?xml version=”1.0”?> <delicious users=”/users” bookmarks=”/bookmarks” tags=”/tags”> <recent start=”1” end=”20” next=”/?start=21&amp;end=40”> <bookmark url=quot;http://www.example.org/something­ interstingquot;  href=quot;/bookmarks/a211528fb5108cddaa4b0d3aeccdbdcfquot;/> ... </recent> </delicious>    
  • 13. GETting Bookmarks GET /bookmarks 200 OK Content­type: application/atom+xml <?xml version=quot;1.0quot;?> <feed xmlns=quot;http://www.w3.org/2005/Atomquot;>   <title>Bookmarks</title>   <entry>     <title>Something interesting</title>     <link href=quot;/bookmarks/a211528fb5108cddaa4b0d3aeccdbdcfquot;/>     <summary>http://example.org/something­intersting</summary>   </entry> </feed>    
  • 14. GETting A Bookmark GET /bookmarks/a211528fb5108cddaa4b0d3aeccdbdcf 200 OK Content­type: application/bookmark+xml <?xml version=quot;1.0quot;?> <bookmark>   <title>Something interesting</title>   <url>http://example.org/something­intersting</url>   <user href=”/users/pauljames”>pauljames</user>   <tags>     <tag href=”/tags/interesting”>interesting</tag>   </tags> </bookmark>    
  • 15. Creating and Updating POST /bookmarks Content­type: application/bookmark+xml ... 201 Created Location: /bookmarks/a211528fb5108cddaa4b0d3aeccdbdcf PUT /bookmarks/a211528fb5108cddaa4b0d3aeccdbdcf Content­type: application/bookmark+xml ... 200 OK    
  • 16. Benefits of Being RESTful ● Better scaling due to stateless communications  ● Better response times due to caching ● Better long­term compatibility due to: ● the capability of document types to evolve without  breaking backwards­compatibility ● the ability to add support for new content types  without reducing support for older content types. ● Do less with more    
  • 17. Finally, some PHP HTTP method $_SERVER['REQUEST_METHOD'] Reading request data $_SERVER['CONTENT_LENGTH'] $_SERVER['CONTENT_TYPE'] POST - $HTTP_RAW_POST_DATA Other HTTP methods - fopen('php://input', 'r') Processing request data SimpleXML, MiniXML, PHP JSON, parse_str, unserialize, unpack, preg_match, etc.    
  • 18. Generating Responses HTTP response codes 200 OK, 201 Created, 204 No Content, 304 Not Modified, 401 Unauthorized, 404 Not Found, 405 Method Not Allowed, 411 Length Required, 415 Unsupported Media Type Generating representations Smarty, PHPFastTemplate, GD, SimpleXML, printf, etc. HTTP caching Expires, Cache-Control, Etag, Last-Modified header('Expires: '.gmdate('D, j M Y H:i:s T', time() +  $cachelength)); header('Cache­Control: max­age='.$cachelength.', must­ revalidate');    
  • 19. Conclusion ● REST is not just about “Web Services” ● Set of best practices for building Web apps ● Give everything a URL ● Use correct HTTP methods ● Use common media types ● Link things together with hypertext    
  • 20. Further Reading ● Roger L. Costello (http://www.xfront.com/REST­ Web­Services.html) ● Paul Prescod (http://www.prescod.net/rest/) ● REST Wiki (http://rest.blueoxen.net/) ● Atom Publishing Protocol  (http://atomenabled.org/developers/protocol/) ● http://del.icio.us/tag/rest    
  • 21.         1 Introduction Questions Overloaded term POX over HTTP? Other HTTP methods? Tidy URLs? Buzzword? http://flickr.com/photos/estherase/128983854/  
  • 22.     Representational State Transfer     2 Architectural style Distilled from the Web by Roy Fielding HTTP 1.1 was designed to conform to REST Defines how the Web works Describes a set of rules for building applications on the  Web that exhibit certain desirable properties REST is not HTTP, but HTTP is RESTful “it’s the way the Web already works, just formalized a bit   and with some do’s and don’ts.” Web service is a Web page that’s meant to be consumed  by an autonomous program as opposed to a Web  browser http://flickr.com/photos/practicalowl/392894653/  
  • 23.     RESTful Principles     3 5 principles ● A universal syntax for resource­identification ­ URLs ● A set of well­defined operations ● Having a shared set of media­types ● The use of hypermedia for application state­transitions ● Stateless protocol – all state on the client http://flickr.com/photos/thowi/113223967/  
  • 24.     A universal syntax for resource-identification     4 ● Uniform resource locators (URLs) ● Every resource (thing of interest) has a URL ● URLs are unique and allow us to dereference a  resource ● Nouns ● Trillions of nouns for all the concepts in all the heads  and files of all the people in the world http://flickr.com/photos/joeholmes/258136938/  
  • 25.     A set of well-defined operations     5 ● HTTP methods ­ verbs ● GET – fetch ● POST ­ append/process ● PUT ­ create/update ● DELETE ­ delete ● Uniform interface, GET always gets, PUT always  creates ● Using different verbs for different nouns would make  widespread communication impossible ● There are no applications you can think of which  cannot be made to fit http://flickr.com/photos/joygant/971783023/  
  • 26.     Having a shared set of media-types     6 ● What's not machine­processable about the current  Web isn't the protocol, it's the content ● Information conveyed via documents ● A standard set of document formats (HTML, RDF,  JPEG, PNG, etc.) ● Representation of a resource ● Resources are just concepts, representations are how  we interact with them http://flickr.com/photos/thefrankfurtschool/1305454450/  
  • 27.     The use of hypermedia for application state-transitions     7 ● Hypertext provides links between resources ● Clients change state (navigate the Web) via information  from a previous state ● URLs are opaque to clients, they never construct URLs ● Because the links mirror the structure of how a user  makes progress through an application ● A Web­based application is a dynamically changing  graph of state representations (pages) and potential  transitions (links) between states ● If not, it may be accessible from the Web, but it’s not  really part of the Web http://flickr.com/photos/pgoyette/100769956/  
  • 28.     Stateless protocol     8 ● Application state is the information necessary to  understand the context of an interaction – auth details,  etc. ● Resource state – S in REST, avoid unnamed state ● All requests must include all application state ● Session state is application state – if you want  a  session you need a smarter client than a browser –  shopping cart ● Prevents partial failures ● Load­balancing ● Service interruptions http://flickr.com/photos/davenyc/23033147/  
  • 29.     Building a RESTful App     9 ● Discover first class objects ● Our resources ● Assign URLs and URL­spaces ● Define representations ● Input and output formats ● Define HTTP methods Time for an Example http://flickr.com/photos/hugovk/2037935886/  
  • 30.     RESTfully Delicious ● Get a list of all bookmarks ● filter by user and/or tag ● limit by number ● Add a bookmark ● Edit a bookmark ● Delete a bookmark     10 Get a list of all bookmarks filter by user and/or tag limit by number Add a bookmark Edit a bookmark Delete a bookmark http://flickr.com/photos/sharynmorrow/124428600/  
  • 31.     Discover Resources Resources URLs Methods Representations Bookmark /bookmarks/{md5} GET application/bookmark+xml PUT application/bookmark+xml DELETE Bookmark list /bookmarks GET application/atom+xml Resources URLs Methods Representations POST application/bookmark+xml User list /users GET application/atom+xml Users bookmarks /users/{user} GET application/atom+xml Tag list /tags GET application/atom+xml Tagged bookmarks /tags/{tag} GET application/atom+xml Homepage / GET application/delicious+xml     11 http://flickr.com/photos/sharynmorrow/124428600/  
  • 32.     GETting the Homepage GET / 200 OK Content­type: application/delicious+xml <?xml version=”1.0”?> <delicious users=”/users” bookmarks=”/bookmarks” tags=”/tags”> <recent start=”1” end=”20” next=”/?start=21&amp;end=40”> <bookmark url=quot;http://www.example.org/something­ interstingquot;  href=quot;/bookmarks/a211528fb5108cddaa4b0d3aeccdbdcfquot;/> ... </recent> </delicious>     12 http://flickr.com/photos/sharynmorrow/124428600/  
  • 33.     GETting Bookmarks GET /bookmarks 200 OK Content­type: application/atom+xml <?xml version=quot;1.0quot;?> <feed xmlns=quot;http://www.w3.org/2005/Atomquot;>   <title>Bookmarks</title>   <entry>     <title>Something interesting</title>     <link href=quot;/bookmarks/a211528fb5108cddaa4b0d3aeccdbdcfquot;/>     <summary>http://example.org/something­intersting</summary>   </entry> </feed>     13 http://flickr.com/photos/sharynmorrow/124428600/  
  • 34.     GETting A Bookmark GET /bookmarks/a211528fb5108cddaa4b0d3aeccdbdcf 200 OK Content­type: application/bookmark+xml <?xml version=quot;1.0quot;?> <bookmark>   <title>Something interesting</title>   <url>http://example.org/something­intersting</url>   <user href=”/users/pauljames”>pauljames</user>   <tags>     <tag href=”/tags/interesting”>interesting</tag>   </tags> </bookmark>     14 http://flickr.com/photos/sharynmorrow/124428600/  
  • 35.     Creating and Updating POST /bookmarks Content­type: application/bookmark+xml ... 201 Created Location: /bookmarks/a211528fb5108cddaa4b0d3aeccdbdcf PUT /bookmarks/a211528fb5108cddaa4b0d3aeccdbdcf Content­type: application/bookmark+xml ... 200 OK     15 http://flickr.com/photos/sharynmorrow/124428600/  
  • 36.     Benefits of Being RESTful ● Better scaling due to stateless communications  ● Better response times due to caching ● Better long­term compatibility due to: ● the capability of document types to evolve without  breaking backwards­compatibility ● the ability to add support for new content types  without reducing support for older content types. ● Do less with more     16 Better scaling due to stateless communications  Better response times due to caching Better long­term compatibility due to: the capability of document types to evolve  without breaking backwards­compatibility the ability to add support for new content types  without reducing support for older content  types. Lower learning curve for consumer Lower support overhead for producer http://flickr.com/photos/ari/1387533615/  
  • 37.     Finally, some PHP HTTP method $_SERVER['REQUEST_METHOD'] Reading request data $_SERVER['CONTENT_LENGTH'] $_SERVER['CONTENT_TYPE'] POST - $HTTP_RAW_POST_DATA Other HTTP methods - fopen('php://input', 'r') Processing request data SimpleXML, MiniXML, PHP JSON, parse_str, unserialize, unpack, preg_match, etc.     17 http://flickr.com/photos/nez/378348754/  
  • 38.     Generating Responses HTTP response codes 200 OK, 201 Created, 204 No Content, 304 Not Modified, 401 Unauthorized, 404 Not Found, 405 Method Not Allowed, 411 Length Required, 415 Unsupported Media Type Generating representations Smarty, PHPFastTemplate, GD, SimpleXML, printf, etc. HTTP caching Expires, Cache-Control, Etag, Last-Modified header('Expires: '.gmdate('D, j M Y H:i:s T', time() +  $cachelength)); header('Cache­Control: max­age='.$cachelength.', must­ revalidate');     18 http://flickr.com/photos/nez/378348754/  
  • 39.     Conclusion ● REST is not just about “Web Services” ● Set of best practices for building Web apps ● Give everything a URL ● Use correct HTTP methods ● Use common media types ● Link things together with hypertext     19 REST is not just about “Web Services” Set of best practices for building Web apps Give everything a URL Use correct HTTP methods Use common media types Link things together with hypertext REST is an architectural style It defines 4 core principles A universal syntax for resource- identification A set of well-defined operations Having a shared set of media-types The use of hypermedia for application state-transitions Stateless client/server interaction   It helps us write well behaved apps
  • 40.     Further Reading ● Roger L. Costello (http://www.xfront.com/REST­ Web­Services.html) ● Paul Prescod (http://www.prescod.net/rest/) ● REST Wiki (http://rest.blueoxen.net/) ● Atom Publishing Protocol  (http://atomenabled.org/developers/protocol/) ● http://del.icio.us/tag/rest     20 http://flickr.com/photos/dhammza/91435718/