Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How the Web Evolves with Hypermedia (IPC2011 2011-10-11)

How the Web Evolves with Hypermedia (IPC2011 2011-10-11)

David Zuelke

October 11, 2011
Tweet

More Decks by David Zuelke

Other Decks in Programming

Transcript

  1. WWW

  2. PROGRESSIVE INTERNATIONAL GMMC-68 ✓ Makes something to eat ✓ Cool

    & evil company name ✓ like “Cyberdyne” ✓ or “Umbrella Corporation” ✓ GMMC-68 sounds like a Terminator model number
  3. while($david-­‐>isBored()&&!$david-­‐>isBroke()){    squeeze_pacman_stress_ball();        $amazon  =  new  Browser('http://amazon.com');

       while(!$david-­‐>getIsHappy())  {        switch($amazon-­‐>state)  {            case  'home':  {                $amazon-­‐>search('awesome  stuff');            }  break;            case  'search_result_page':  {                if(!$amazon-­‐>hasSomethingAwesome())  {                    $amazon-­‐>followAwesomeProduct();                }  elseif($amazon-­‐>hasMorePages())  {                    $amazon-­‐>followNextPage();                }  else  {                    sleep(3600);                    $amazon-­‐>state  =  'home';  //  retry!                }            }  break;            case  'product_page':  {                $amazon-­‐>followAddToCart();            }  break;            case  'shopping_cart':  {                $amazon-­‐>followCheckout();            }  break;            case  'login_or_register':  {                if($david-­‐>hasAmazonAccount())  {                    $amazon-­‐>followLogin();                }  else  {                    $amazon-­‐>followRegister();                }            }  break;            case  'order_summary':  {                $amazon-­‐>followConfirmation();            }  break;            case  'order_confirmation':  {                $david-­‐>setIsHappy(mt_rand(0,1));            }  break;            case  'default':  {                $amazon-­‐>state  =  'home';            }        }    } } AS PSEUDOCODE
  4. CAN WE TEACH A COMPUTER TO... • ... discover workflows

    the server offers? • ... follow links to a “next page” until the right product is found? • ... leniently handle... • ... changes in organization of resources? • ... newly added information or operations?
  5. yes

  6. I am getting frustrated by the number of people calling

    any HTTP-based interface a REST API [...] If the engine of application state (and hence the API) is not being driven by hypertext, then it cannot be RESTful and cannot be a REST API. His Royness Fielding
  7. <?xml  version="1.0"  encoding="utf-­‐8"  standalone="yes"?> <search>    <total_results>9</total_results>    <items_per_page>1</items_per_page>  

     <start_index>1</start_index>    <link  href="http://openapi.lovefilm.com/catalog/games?start_index=1&amp;items_per_page=1&amp;term=old"                rel="self"  title="self"/>    <link  href="http://openapi.lovefilm.com/catalog/games?start_index=2&amp;items_per_page=1&amp;term=old"                rel="next"  title="next"/>    <link  href="http://openapi.lovefilm.com/catalog/games?start_index=9&amp;items_per_page=1&amp;term=old"                rel="last"  title="last"/>    <catalog_title>        <can_rent>true</can_rent>        <release_date>2003-­‐09-­‐12</release_date>        <title  full="Star  Wars:  Knights  of  the  Old  Republic"  clean="Star  Wars:  Knights  of  the  Old  Republic"/>        <id>http://openapi.lovefilm.com/catalog/title/59643</id>        <adult>false</adult>        <number_of_ratings>574</number_of_ratings>        <rating>4</rating>        <category  scheme="http://openapi.lovefilm.com/categories/catalog"  term="games"/>        <category  scheme="http://openapi.lovefilm.com/categories/format"  term="Xbox"/>        <category  scheme="http://openapi.lovefilm.com/categories/genres"  term="Adventure"/>        <category  scheme="http://openapi.lovefilm.com/categories/genres"  term="Role-­‐playing"/>        <category  scheme="http://openapi.lovefilm.com/categories/certificates/bbfc"  term="TBC"/>        <link  href="http://openapi.lovefilm.com/catalog/title/59643/synopsis"                    rel="http://schemas.lovefilm.com/synopsis"  title="synopsis"/>        <link  href="http://openapi.lovefilm.com/catalog/title/59643/reviews"                    rel="http://schemas.lovefilm.com/reviews"  title="reviews"/>        <link  href="http://www.lovefilm.com/product/59643-­‐Star-­‐Wars-­‐Knights-­‐of-­‐the-­‐Old-­‐Republic.html?cid=LFAPI"                    rel="alternate"  title="web  page"/>    </catalog_title> </search>
  8. GET  /products/1234  HTTP/1.1 Host:  evil.com Accept:  application/vnd.com.evil.shop+xml HTTP/1.1  200  OK

    Content-­‐Type:  application/vnd.com.evil.shop+xml;  charset=utf-­‐8 Allow:  GET,  PUT,  DELETE <?xml  version="1.0"  encoding="utf-­‐8"?> <product  xmlns="urn:com.evil.prods"  xmlns:atom="http://www.w3.org/2005/Atom">    <id>1234</id>    <name>Shark  with  Friggin’  Laser  Beams  Attached  to  its  Head</name>    <price  currency="EUR">3.14</price>    <atom:link  rel="category"  type="application/vnd.com.evil.shop+xml"                          href="http://evil.com/categories/lasers"/> </product>
  9. PUT  /products/1234  HTTP/1.1 Host:  evil.com Content-­‐Type:  application/vnd.com.evil.shop+xml <?xml  version="1.0"  encoding="utf-­‐8"?>

    <product  xmlns="urn:com.evil.prods"  xmlns:atom="http://www.w3.org/2005/Atom">    <id>1234</id>    <name>Shark  with  Friggin’  Laser  Beams  Attached  to  its  Head</name>    <price  currency="EUR">31414.14</price>    <atom:link  rel="category"  type="application/vnd.com.evil.shop+xml"                          href="http://evil.com/categories/lasers"/> </product> HTTP/1.1  204  No  Content Content-­‐Type:  application/vnd.com.evil.shop+xml;  charset=utf-­‐8 Allow:  GET,  PUT,  DELETE
  10. <?xml  version="1.0"  encoding="utf-­‐8"?> <products  xmlns="http://acme.com/shop/products">    <product  id="123">    

       <name>Bacon</name>        <price>5.99</price>        OMNOMNOM  Bacon    </product> </products>
  11. <?xml  version="1.0"  encoding="utf-­‐8"?> <products  xmlns="http://acme.com/shop/products">    <product  id="123">    

       <name>Bacon</name>        <price>5.99</price>        <price  currency="EUR">4.49</price>    </product> </products>
  12. <?xml  version="1.0"  encoding="utf-­‐8"?> <products  xmlns="http://acme.com/shop/products">    <product  id="123">    

       <name  xml:lang="en">Bacon</name>        <name  xml:lang="de">Speck</name>        <price>5.99</price>    </product> </products>
  13. <?xml  version="1.0"  encoding="utf-­‐8"?> <products  xmlns="http://acme.com/shop/products">    <product  id="123">    

       <name  xml:lang="en">Bacon</name>        <name  xml:lang="de">Speck</name>        <price>5.99</price>        <link  rel="category"  href="..."  />    </product> </products>