SlideShare una empresa de Scribd logo
1 de 40
Descargar para leer sin conexión
     
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/




 

Más contenido relacionado

La actualidad más candente

Drawing the Line with Browser Compatibility
Drawing the Line with Browser CompatibilityDrawing the Line with Browser Compatibility
Drawing the Line with Browser Compatibility
jsmith92
 
Doctype html
Doctype htmlDoctype html
Doctype html
Eddy_TKJ
 
LESS is More
LESS is MoreLESS is More
LESS is More
jsmith92
 
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
davyjones
 
Yahoo Communities Architecture Unlikely Bedfellows
Yahoo Communities Architecture Unlikely BedfellowsYahoo Communities Architecture Unlikely Bedfellows
Yahoo Communities Architecture Unlikely Bedfellows
ConSanFrancisco123
 

La actualidad más candente (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
 

Destacado

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
webhostingguy
 
Apache web server
Apache web serverApache web server
Apache web server
zrstoppe
 
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
Ba Quynh Nguyen
 
Apache Web server Complete Guide
Apache Web server Complete GuideApache Web server Complete Guide
Apache Web server Complete Guide
webhostingguy
 
01 principles of the wcdma system
01 principles of the wcdma system01 principles of the wcdma system
01 principles of the wcdma system
khurrambilal01
 

Destacado (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 a REST Introduction (PHP London)

Applications of the REST Principle
Applications of the REST PrincipleApplications of the REST Principle
Applications of the REST Principle
elliando dias
 

Similar a REST Introduction (PHP London) (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
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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...
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

REST Introduction (PHP London)

  • 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/