SlideShare uma empresa Scribd logo
1 de 24
Baixar para ler offline
Fulfilling the Hypermedia Constraint
Via HTTP OPTIONS, the HTTP
Vocabulary In RDF, And Link Headers
Second International Workshop on RESTful Design
WWW 2011, 28 March 2011, Hyderabad, India

Thomas Steiner, @tomayac
Google Germany GmbH, Universitat Politècnica de Catalunya

Jan Algermissen, @algermissen
NORD Software Consulting
Towards the full glory of REST




             Sitting on an HTTP API is not RESTing.
Towards the full glory of REST




          Slouching on a hypermedia API is RESTing.
Towards the full glory of REST



                  aka. hypermedia
        "When I say hypertext, I mean the
        simultaneous presentation of
        information and controls such that
        the information becomes the
        affordance through which the user
        (or automaton) obtains choices and
        selects actions."
Towards the full glory of REST



   Simultaneous presentation of information and controls.


                                   Next




                                   Fridge
Information
                                    Controls
                          State
Hypermedia controls in the Atom Syndication protocol (RFC4287)




 atomLink = element atom:link {
     atomCommonAttributes,
     attribute href { atomUri },
     attribute rel { atomNCName | atomUri }?,
     attribute type { atomMediaType }?,
     attribute hreflang { atomLanguageTag }?,
     attribute title { text }?,
     attribute length { text }?,
     undefinedContent }

 •  Registry of link relations:
    http://tools.ietf.org/html/rfc4287#page-31.
 •  Can be an IRI for custom link relations.
Hypermedia controls in the Google Data protocol




•  Based on Atom Syndication protocol.
•  XML and JSON serialization.
Hypermedia controls in forms




•  Can use the XHTML @role attribute.
Hypermedia controls in media types




•  Versioning happens via the media type.
•  Can use the vendor (vnd.) or personal (prs.) tree.
Hypermedia controls in link headers


$ curl -i http://search.example.org/page8
HTTP/1.1 200 OK
Date: Fri, 25 Mar 2011 08:24:20 GMT
Server: Apache
Last-Modified: Fri, 18 Feb 2011 08:30:51 GMT
ETag: "d1caaa08-8aa-4d5e2e3b"
Link: <http://search.example.org/page7>; rel="previous";
title="previous results"
Link: <http://search.example.org/page9>; rel="next";
title="next results"
Content-Length: 2218
Content-Type: text/html

•  Semantically equivalent to HTML link, atom:link.
•  Web Linking RFC updates Atom link relations:
   http://tools.ietf.org/html/rfc5988#section-6.2.2.
HTTP OPTIONS


$ curl -i -X OPTIONS http://www.upc.edu/
HTTP/1.1 200 OK
Allow: GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE

•  On HTTP OPTIONS from RFC2616 (
   http://tools.ietf.org/html/rfc2616#section-9.2):
•  The OPTIONS method represents a request
   for information about the communication options
   available on the request/response chain.
•  A 200 response SHOULD include any header fields that
   indicate optional features implemented by the server and
   applicable to that resource (e.g., Allow).
•  The response body, if any, SHOULD
   include information about the communication options.
•  OPTIONS is an optional method. Servers are not
   required to support it.
Building the bridge to Linked Data


•  Atom, Google Data, HTML Link, XHTML @role, Link
   headers can use extension relation types via URIs†.
•  With Linked Data, when you have some of it, you can find
   other, related, data.
•  Tim Berners-Lee's Linked Data principles (
   http://www.w3.org/DesignIssues/LinkedData.html):
    1. Use URIs as names for things.
    2. Use HTTP URIs so that people can
       look up those names.
    3. When someone looks up a URI,
       provide useful information using the
       standards (RDF*, SPARQL).
    4. Include links to other URIs, so that
       they can discover more things.
   †For   Atom even IRIs, limiting ourselves to URIs here.
Modeling HTTP in RDF


•  HTTP Vocabulary in RDF intended to record HTTP(S)
   request and response messages, including the various
   headers (http://www.w3.org/TR/HTTP-in-RDF10/).

$ curl -H "Accept: text/turtle" http://dbpedia.org

_:req a http:Request ;
  http:httpVersion "1.1" ;
  http:methodName "GET" ;
  http:mthd <http://www.w3.org/2008/http-methods#GET> ;
  http:headers (
    [ http:fieldName "Host" ;
      http:fieldValue "dbpedia.org" ;
      http:hdrName <[…]w3.org/2008/http-header#host> ]
    [ http:fieldName "Accept" ;
      http:fieldValue "text/turtle" ;
      http:hdrName <[…]w3.org/2008/http-header#accept> ]
  ) .
Bringing it all together


1. Link headers to transparently inject data into an HTTP
   response without touching the body.
2. HTTP OPTIONS as a means of requesting communication
   options information.
3. HTTP Vocabulary in RDF for modeling HTTP
   communication.

•  Real-world example: API for annotating YouTube videos
   with RDF:

                                    API


                          In: YouTube video ID
                   Out: text/turtle, application/rdf+xml
Bringing it all together


•  User agents can GET an RDF representation of a video.
•  Generic string with meta information "this is a YouTube ID"
   as input by API definition.
•  Generic output media types by API definition.
•  RDF output document can be manually corrected via PUT,
   or DELETEed.

$ curl -i -X GET -H "Accept: text/turtle" http://
api.example.org/youtube/videos/o4T9_MduMEQ



                                    API


                          In: YouTube video ID
                   Out: text/turtle, application/rdf+xml
Bringing it all together


•  Nice to document input constraints (YouTube ID).

                   API

•  Nice to document next steps based on the output.

          API


•  Can use a combination of OPTIONS, Link headers, and
   HTTP Vocabulary in RDF to do this transparently.
   o  Send next steps (media controls) as Link headers.
   o  Document constraints for each request via OPTIONS.
Bringing it all together

$ curl -i -X OPTIONS http://api.example.org/youtube/videos
HTTP/1.1 200 OK
Content-Type: text/turtle; charset=utf-8
Link: <http://api.example.org/youtube/videos/{video_id}>; rel="related"
Allow: GET, PUT, DELETE, HEAD, OPTIONS, PATCH
Content-Length: xx

_:req_1 a http:Request ;
  http:httpVersion "1.1" ;
  http:methodName "GET" ;
    …

_:req_2 a http:Request ;
  http:httpVersion "1.1" ;
  http:methodName "PUT" ;
    …

_:req_3 a http:Request ;
  http:httpVersion "1.1" ;
  http:methodName "DELETE" ;
    …
Bringing it all together

$ curl -i -X OPTIONS http://api.example.org/youtube/videos
…
Link: <http://api.example.org/youtube/videos/{video_id}>; rel="related"
Allow: GET, HEAD, PUT, DELETE, OPTIONS, PATCH
…


_:req_1 a http:Request ;
  http:httpVersion "1.1" ;
  http:methodName "GET" ;
  http:mthd <http://www.w3.org/2008/http-methods#GET> ;
  exHttp:prefixPath "/youtube/" ;
  exHttp:suffixPath [
    a api:uriTemplate ;
    a yt:videoid ;
  ] ;
  http:headers (
    [ http:fieldName "Host" ;
      http:fieldValue "api.example.org" ;
      http:hdrName <http://www.w3.org/2008/http-header#host>
    ]
  ) .
Bringing it all together

_:req_1 a http:Request ;
  http:httpVersion "1.1" ;
  http:methodName "GET" ;
  http:mthd <http://www.w3.org/2008/http-methods#GET> ;
  exHttp:prefixPath "/youtube/" ;
  exHttp:suffixPath [
    a api:uriTemplate ;
    a yt:videoid ;
  ] ;
  http:headers (
    [ http:fieldName "Host" ;
      http:fieldValue "api.example.org" ;
      http:hdrName <http://www.w3.org/2008/http-header#host>
    ]
  ) .

exHttp: Suggested extension of the HTTP Vocabulary in
RDF for splitting http:abs_path (/foo/bar) in
exHttp:prefixPath (/foo) and exHttp:suffixPath
(/bar).
Bringing it all together

_:req_1 a http:Request ;
  http:httpVersion "1.1" ;
  http:methodName "GET" ;
  http:mthd <http://www.w3.org/2008/http-methods#GET> ;
  exHttp:prefixPath "/youtube/" ;
  exHttp:suffixPath [
    a api:uriTemplate ;
    a yt:videoid ;
  ] ;
  http:headers (
    [ http:fieldName "Host" ;
      http:fieldValue "api.example.org" ;
      http:hdrName <http://www.w3.org/2008/http-header#host>
    ]
  ) .

api:uriTemplate: Borrowed from
http://purl.org/linked-data/api/vocab# in order to model URI
templates.
Bringing it all together

_:req_1 a http:Request ;
  http:httpVersion "1.1" ;
  http:methodName "GET" ;
  http:mthd <http://www.w3.org/2008/http-methods#GET> ;
  exHttp:prefixPath "/youtube/" ;
  exHttp:suffixPath [
    a api:uriTemplate ;
    a yt:videoid ;
  ] ;
  http:headers (
    [ http:fieldName "Host" ;
      http:fieldValue "api.example.org" ;
      http:hdrName <http://www.w3.org/2008/http-header#host>
    ]
  ) .

yt:videoid: Defines the URI template to be a YouTube
video ID (http://gdata.youtube.com/schemas/2007/videoid).
Criticism


•  The approach might encourage tight coupling. Evil?
   Depends. Might be OK if user agents evaluate their
   OPTIONS at runtime.
•  HTTP Vocabulary in RDF might be too verbose, but it's a
   standard, and usually a bad standard is better than no
   standard.
•  Total freedom (=chaos?) with regards to the RDF triples.
   Fair enough. However, extension relation types via URLs
   require human interaction as well.
Thanks for your attention


•  Thomas Steiner
    o  tomac@google.com
    o  @tomayac
Image credits

Lawn chair - http://www.cp-objekt.de/hundemoebel/Klappstuhl-Montana-st-426710-gr.jpg
Poäng - http://www.ikea.com/au/en/catalog/products/10157948
Roy Fielding - http://upload.wikimedia.org/wikipedia/commons/thumb/c/cd/Roy_Fielding.jpg/450px-Roy_Fielding.jpg
Direction sign - http://www.myparkingsign.com/img/lg/X/One-Direction-Arrow-Sign-X-W1-6L.gif
Remote control - http://www.faqs.org/photo-dict/photofiles/list/824/1251remote_control.jpg
LCD TV - http://www.slashgear.com/wp-content/uploads/2009/02/philips_nettv-480x370.jpg
Fridge - http://modculture.typepad.com/photos/uncategorized/2008/06/13/smeg_mini.jpg
Linked Data mug - http://www.w3.org/DesignIssues/diagrams/lod/480759174v0_350x350_Back.jpg
Cloud - http://www.clipart.clipartist.net/openclipart/clipart/signs_and_symbols/weather/w_cloud_xxl.png
Dr. Evil - http://upload.wikimedia.org/wikipedia/en/1/16/Drevil_million_dollars.jpg




                                                                        Fridge

Mais conteúdo relacionado

Mais procurados

Saveface - Save your Facebook content as RDF data
Saveface - Save your Facebook content as RDF dataSaveface - Save your Facebook content as RDF data
Saveface - Save your Facebook content as RDF dataFuming Shih
 
Your rest api using laravel
Your rest api using laravelYour rest api using laravel
Your rest api using laravelSulaeman .
 
Building Awesome APIs with Lumen
Building Awesome APIs with LumenBuilding Awesome APIs with Lumen
Building Awesome APIs with LumenKit Brennan
 
An Introduction to Solr
An Introduction to SolrAn Introduction to Solr
An Introduction to Solrtomhill
 
Cwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey IntroductionseyCwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey Introductionseyelliando dias
 
Deepak khetawat sling_models_sightly_jsp
Deepak khetawat sling_models_sightly_jspDeepak khetawat sling_models_sightly_jsp
Deepak khetawat sling_models_sightly_jspDEEPAK KHETAWAT
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...Guillaume Laforge
 
Jumpstart Django
Jumpstart DjangoJumpstart Django
Jumpstart Djangoryates
 
Python & Django TTT
Python & Django TTTPython & Django TTT
Python & Django TTTkevinvw
 
Introduction To Ant
Introduction To AntIntroduction To Ant
Introduction To AntRajesh Kumar
 
Developing web apps using Erlang-Web
Developing web apps using Erlang-WebDeveloping web apps using Erlang-Web
Developing web apps using Erlang-Webfanqstefan
 
Feed the Masses
Feed the MassesFeed the Masses
Feed the Massespbugni
 
170517 damien gérard framework facebook
170517 damien gérard   framework facebook170517 damien gérard   framework facebook
170517 damien gérard framework facebookGeeks Anonymes
 
MetaCPAN, Mojolicious and OpenAPI
MetaCPAN, Mojolicious and OpenAPIMetaCPAN, Mojolicious and OpenAPI
MetaCPAN, Mojolicious and OpenAPIShawn Sorichetti
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHPZoran Jeremic
 
DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and Python
DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and PythonDEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and Python
DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and PythonCisco DevNet
 
Introduction to RESTful Web Services
Introduction to RESTful Web ServicesIntroduction to RESTful Web Services
Introduction to RESTful Web ServicesFelipe Dornelas
 

Mais procurados (20)

Saveface - Save your Facebook content as RDF data
Saveface - Save your Facebook content as RDF dataSaveface - Save your Facebook content as RDF data
Saveface - Save your Facebook content as RDF data
 
Your rest api using laravel
Your rest api using laravelYour rest api using laravel
Your rest api using laravel
 
Building Awesome APIs with Lumen
Building Awesome APIs with LumenBuilding Awesome APIs with Lumen
Building Awesome APIs with Lumen
 
An Introduction to Solr
An Introduction to SolrAn Introduction to Solr
An Introduction to Solr
 
Cwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey IntroductionseyCwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey Introductionsey
 
Deepak khetawat sling_models_sightly_jsp
Deepak khetawat sling_models_sightly_jspDeepak khetawat sling_models_sightly_jsp
Deepak khetawat sling_models_sightly_jsp
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
 
Jumpstart Django
Jumpstart DjangoJumpstart Django
Jumpstart Django
 
Python & Django TTT
Python & Django TTTPython & Django TTT
Python & Django TTT
 
Introduction To Ant
Introduction To AntIntroduction To Ant
Introduction To Ant
 
FOAF
FOAFFOAF
FOAF
 
ASP.NET WEB API
ASP.NET WEB APIASP.NET WEB API
ASP.NET WEB API
 
Developing web apps using Erlang-Web
Developing web apps using Erlang-WebDeveloping web apps using Erlang-Web
Developing web apps using Erlang-Web
 
Feed the Masses
Feed the MassesFeed the Masses
Feed the Masses
 
REST API Laravel
REST API LaravelREST API Laravel
REST API Laravel
 
170517 damien gérard framework facebook
170517 damien gérard   framework facebook170517 damien gérard   framework facebook
170517 damien gérard framework facebook
 
MetaCPAN, Mojolicious and OpenAPI
MetaCPAN, Mojolicious and OpenAPIMetaCPAN, Mojolicious and OpenAPI
MetaCPAN, Mojolicious and OpenAPI
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHP
 
DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and Python
DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and PythonDEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and Python
DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and Python
 
Introduction to RESTful Web Services
Introduction to RESTful Web ServicesIntroduction to RESTful Web Services
Introduction to RESTful Web Services
 

Destaque

RestFS: Resources and Services are Filesystems, Too
RestFS: Resources and Services are Filesystems, TooRestFS: Resources and Services are Filesystems, Too
RestFS: Resources and Services are Filesystems, Tooruyalarcon
 
IT復興円卓会議資料
IT復興円卓会議資料IT復興円卓会議資料
IT復興円卓会議資料Ishii Miho
 
A Resource Oriented Framework for Context-Aware Enterprise Applications
A Resource Oriented Framework for Context-Aware Enterprise ApplicationsA Resource Oriented Framework for Context-Aware Enterprise Applications
A Resource Oriented Framework for Context-Aware Enterprise Applicationsruyalarcon
 
Cspd san fran2011
Cspd san fran2011Cspd san fran2011
Cspd san fran2011tbg-designs
 
XML Technologies for RESTful Services Development
XML Technologies for RESTful Services DevelopmentXML Technologies for RESTful Services Development
XML Technologies for RESTful Services Developmentruyalarcon
 
Hecate, Managing Authorization with RESTful XML
Hecate, Managing Authorization with RESTful XMLHecate, Managing Authorization with RESTful XML
Hecate, Managing Authorization with RESTful XMLruyalarcon
 
ISPPについて
ISPPについてISPPについて
ISPPについてIshii Miho
 
Xtremekeratincare.com
Xtremekeratincare.comXtremekeratincare.com
Xtremekeratincare.comxtremekeratin
 
IT復興円卓会議資料
IT復興円卓会議資料IT復興円卓会議資料
IT復興円卓会議資料Ishii Miho
 
Sustainable Compliance For PCI DSS Standard
Sustainable Compliance For PCI DSS StandardSustainable Compliance For PCI DSS Standard
Sustainable Compliance For PCI DSS StandardChristian Frahm
 
Wsrest13 gilherme keynote
Wsrest13 gilherme keynoteWsrest13 gilherme keynote
Wsrest13 gilherme keynoteruyalarcon
 

Destaque (20)

English class 4
English class 4English class 4
English class 4
 
RestFS: Resources and Services are Filesystems, Too
RestFS: Resources and Services are Filesystems, TooRestFS: Resources and Services are Filesystems, Too
RestFS: Resources and Services are Filesystems, Too
 
Life Support
Life SupportLife Support
Life Support
 
IT復興円卓会議資料
IT復興円卓会議資料IT復興円卓会議資料
IT復興円卓会議資料
 
A Resource Oriented Framework for Context-Aware Enterprise Applications
A Resource Oriented Framework for Context-Aware Enterprise ApplicationsA Resource Oriented Framework for Context-Aware Enterprise Applications
A Resource Oriented Framework for Context-Aware Enterprise Applications
 
2015 State of the Industry - LOGA Don Briggs
2015 State of the Industry - LOGA Don Briggs2015 State of the Industry - LOGA Don Briggs
2015 State of the Industry - LOGA Don Briggs
 
Cspd san fran2011
Cspd san fran2011Cspd san fran2011
Cspd san fran2011
 
XML Technologies for RESTful Services Development
XML Technologies for RESTful Services DevelopmentXML Technologies for RESTful Services Development
XML Technologies for RESTful Services Development
 
Hecate, Managing Authorization with RESTful XML
Hecate, Managing Authorization with RESTful XMLHecate, Managing Authorization with RESTful XML
Hecate, Managing Authorization with RESTful XML
 
S1 intro
S1 introS1 intro
S1 intro
 
Meetup intro presentation
Meetup intro presentationMeetup intro presentation
Meetup intro presentation
 
ISPPについて
ISPPについてISPPについて
ISPPについて
 
Xtremekeratincare.com
Xtremekeratincare.comXtremekeratincare.com
Xtremekeratincare.com
 
The Red Sea Crossing
The Red Sea CrossingThe Red Sea Crossing
The Red Sea Crossing
 
Presentación ingles evet2edu
Presentación ingles evet2eduPresentación ingles evet2edu
Presentación ingles evet2edu
 
Xtremekeratincare
XtremekeratincareXtremekeratincare
Xtremekeratincare
 
IT復興円卓会議資料
IT復興円卓会議資料IT復興円卓会議資料
IT復興円卓会議資料
 
Sustainable Compliance For PCI DSS Standard
Sustainable Compliance For PCI DSS StandardSustainable Compliance For PCI DSS Standard
Sustainable Compliance For PCI DSS Standard
 
Wsrest13 gilherme keynote
Wsrest13 gilherme keynoteWsrest13 gilherme keynote
Wsrest13 gilherme keynote
 
Propuesta grupal
Propuesta grupal Propuesta grupal
Propuesta grupal
 

Semelhante a Fulfilling Hypermedia Constraints Via HTTP Options

ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiTiago Knoch
 
KMUTNB - Internet Programming 2/7
KMUTNB - Internet Programming 2/7KMUTNB - Internet Programming 2/7
KMUTNB - Internet Programming 2/7phuphax
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSCarol McDonald
 
ASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsIdo Flatow
 
Designing RESTful APIs
Designing RESTful APIsDesigning RESTful APIs
Designing RESTful APIsanandology
 
01. http basics v27
01. http basics v2701. http basics v27
01. http basics v27Eoin Keary
 
Boost Your Content Strategy for REST APIs with Gururaj BS
Boost Your Content Strategy for REST APIs with Gururaj BSBoost Your Content Strategy for REST APIs with Gururaj BS
Boost Your Content Strategy for REST APIs with Gururaj BSInformation Development World
 
Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01raviIITRoorkee
 
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...Nguyen Duc Phu
 
Services in Drupal 8
Services in Drupal 8Services in Drupal 8
Services in Drupal 8Andrei Jechiu
 
Resource-Oriented Web Services
Resource-Oriented Web ServicesResource-Oriented Web Services
Resource-Oriented Web ServicesBradley Holt
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座Li Yi
 
Application integration with the W3C Linked Data standards
Application integration with the W3C Linked Data standardsApplication integration with the W3C Linked Data standards
Application integration with the W3C Linked Data standardsNandana Mihindukulasooriya
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011Shreedhar Ganapathy
 

Semelhante a Fulfilling Hypermedia Constraints Via HTTP Options (20)

ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
KMUTNB - Internet Programming 2/7
KMUTNB - Internet Programming 2/7KMUTNB - Internet Programming 2/7
KMUTNB - Internet Programming 2/7
 
Spider Course Day 1
Spider Course Day 1Spider Course Day 1
Spider Course Day 1
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
ASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP Fundamentals
 
11 asp.net web api
11 asp.net web api11 asp.net web api
11 asp.net web api
 
Designing RESTful APIs
Designing RESTful APIsDesigning RESTful APIs
Designing RESTful APIs
 
01. http basics v27
01. http basics v2701. http basics v27
01. http basics v27
 
HTTP & HTML & Web
HTTP & HTML & WebHTTP & HTML & Web
HTTP & HTML & Web
 
Boost Your Content Strategy for REST APIs with Gururaj BS
Boost Your Content Strategy for REST APIs with Gururaj BSBoost Your Content Strategy for REST APIs with Gururaj BS
Boost Your Content Strategy for REST APIs with Gururaj BS
 
Web services tutorial
Web services tutorialWeb services tutorial
Web services tutorial
 
Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01
 
Web Services Tutorial
Web Services TutorialWeb Services Tutorial
Web Services Tutorial
 
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
 
Services in Drupal 8
Services in Drupal 8Services in Drupal 8
Services in Drupal 8
 
Resource-Oriented Web Services
Resource-Oriented Web ServicesResource-Oriented Web Services
Resource-Oriented Web Services
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
 
Application integration with the W3C Linked Data standards
Application integration with the W3C Linked Data standardsApplication integration with the W3C Linked Data standards
Application integration with the W3C Linked Data standards
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011
 
2007 03 12 Swecr 2
2007 03 12 Swecr 22007 03 12 Swecr 2
2007 03 12 Swecr 2
 

Mais de ruyalarcon

A Framework for Self-descriptive RESTful Services
A Framework for Self-descriptive RESTful ServicesA Framework for Self-descriptive RESTful Services
A Framework for Self-descriptive RESTful Servicesruyalarcon
 
Distributed affordance: An Open-World Assumption for Hypermedia
Distributed affordance: An Open-World Assumption for HypermediaDistributed affordance: An Open-World Assumption for Hypermedia
Distributed affordance: An Open-World Assumption for Hypermediaruyalarcon
 
Teaching Old Services New Tricks: Adding HATEOAS Support as an Afterthought
Teaching Old Services New Tricks: Adding HATEOAS Support as an AfterthoughtTeaching Old Services New Tricks: Adding HATEOAS Support as an Afterthought
Teaching Old Services New Tricks: Adding HATEOAS Support as an Afterthoughtruyalarcon
 
Modeling RESTful applications
Modeling RESTful applicationsModeling RESTful applications
Modeling RESTful applicationsruyalarcon
 
A Framework for Obligation Fulfillment in REST Services
A Framework for Obligation Fulfillment in REST ServicesA Framework for Obligation Fulfillment in REST Services
A Framework for Obligation Fulfillment in REST Servicesruyalarcon
 
REST and Linked Data: a match made for domain driven development?
REST and Linked Data: a match made for domain driven development?REST and Linked Data: a match made for domain driven development?
REST and Linked Data: a match made for domain driven development?ruyalarcon
 

Mais de ruyalarcon (6)

A Framework for Self-descriptive RESTful Services
A Framework for Self-descriptive RESTful ServicesA Framework for Self-descriptive RESTful Services
A Framework for Self-descriptive RESTful Services
 
Distributed affordance: An Open-World Assumption for Hypermedia
Distributed affordance: An Open-World Assumption for HypermediaDistributed affordance: An Open-World Assumption for Hypermedia
Distributed affordance: An Open-World Assumption for Hypermedia
 
Teaching Old Services New Tricks: Adding HATEOAS Support as an Afterthought
Teaching Old Services New Tricks: Adding HATEOAS Support as an AfterthoughtTeaching Old Services New Tricks: Adding HATEOAS Support as an Afterthought
Teaching Old Services New Tricks: Adding HATEOAS Support as an Afterthought
 
Modeling RESTful applications
Modeling RESTful applicationsModeling RESTful applications
Modeling RESTful applications
 
A Framework for Obligation Fulfillment in REST Services
A Framework for Obligation Fulfillment in REST ServicesA Framework for Obligation Fulfillment in REST Services
A Framework for Obligation Fulfillment in REST Services
 
REST and Linked Data: a match made for domain driven development?
REST and Linked Data: a match made for domain driven development?REST and Linked Data: a match made for domain driven development?
REST and Linked Data: a match made for domain driven development?
 

Fulfilling Hypermedia Constraints Via HTTP Options

  • 1. Fulfilling the Hypermedia Constraint Via HTTP OPTIONS, the HTTP Vocabulary In RDF, And Link Headers Second International Workshop on RESTful Design WWW 2011, 28 March 2011, Hyderabad, India Thomas Steiner, @tomayac Google Germany GmbH, Universitat Politècnica de Catalunya Jan Algermissen, @algermissen NORD Software Consulting
  • 2. Towards the full glory of REST Sitting on an HTTP API is not RESTing.
  • 3. Towards the full glory of REST Slouching on a hypermedia API is RESTing.
  • 4. Towards the full glory of REST aka. hypermedia "When I say hypertext, I mean the simultaneous presentation of information and controls such that the information becomes the affordance through which the user (or automaton) obtains choices and selects actions."
  • 5. Towards the full glory of REST Simultaneous presentation of information and controls. Next Fridge Information Controls State
  • 6. Hypermedia controls in the Atom Syndication protocol (RFC4287) atomLink = element atom:link { atomCommonAttributes, attribute href { atomUri }, attribute rel { atomNCName | atomUri }?, attribute type { atomMediaType }?, attribute hreflang { atomLanguageTag }?, attribute title { text }?, attribute length { text }?, undefinedContent } •  Registry of link relations: http://tools.ietf.org/html/rfc4287#page-31. •  Can be an IRI for custom link relations.
  • 7. Hypermedia controls in the Google Data protocol •  Based on Atom Syndication protocol. •  XML and JSON serialization.
  • 8. Hypermedia controls in forms •  Can use the XHTML @role attribute.
  • 9. Hypermedia controls in media types •  Versioning happens via the media type. •  Can use the vendor (vnd.) or personal (prs.) tree.
  • 10. Hypermedia controls in link headers $ curl -i http://search.example.org/page8 HTTP/1.1 200 OK Date: Fri, 25 Mar 2011 08:24:20 GMT Server: Apache Last-Modified: Fri, 18 Feb 2011 08:30:51 GMT ETag: "d1caaa08-8aa-4d5e2e3b" Link: <http://search.example.org/page7>; rel="previous"; title="previous results" Link: <http://search.example.org/page9>; rel="next"; title="next results" Content-Length: 2218 Content-Type: text/html •  Semantically equivalent to HTML link, atom:link. •  Web Linking RFC updates Atom link relations: http://tools.ietf.org/html/rfc5988#section-6.2.2.
  • 11. HTTP OPTIONS $ curl -i -X OPTIONS http://www.upc.edu/ HTTP/1.1 200 OK Allow: GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE •  On HTTP OPTIONS from RFC2616 ( http://tools.ietf.org/html/rfc2616#section-9.2): •  The OPTIONS method represents a request for information about the communication options available on the request/response chain. •  A 200 response SHOULD include any header fields that indicate optional features implemented by the server and applicable to that resource (e.g., Allow). •  The response body, if any, SHOULD include information about the communication options. •  OPTIONS is an optional method. Servers are not required to support it.
  • 12. Building the bridge to Linked Data •  Atom, Google Data, HTML Link, XHTML @role, Link headers can use extension relation types via URIs†. •  With Linked Data, when you have some of it, you can find other, related, data. •  Tim Berners-Lee's Linked Data principles ( http://www.w3.org/DesignIssues/LinkedData.html): 1. Use URIs as names for things. 2. Use HTTP URIs so that people can look up those names. 3. When someone looks up a URI, provide useful information using the standards (RDF*, SPARQL). 4. Include links to other URIs, so that they can discover more things. †For Atom even IRIs, limiting ourselves to URIs here.
  • 13. Modeling HTTP in RDF •  HTTP Vocabulary in RDF intended to record HTTP(S) request and response messages, including the various headers (http://www.w3.org/TR/HTTP-in-RDF10/). $ curl -H "Accept: text/turtle" http://dbpedia.org _:req a http:Request ; http:httpVersion "1.1" ; http:methodName "GET" ; http:mthd <http://www.w3.org/2008/http-methods#GET> ; http:headers ( [ http:fieldName "Host" ; http:fieldValue "dbpedia.org" ; http:hdrName <[…]w3.org/2008/http-header#host> ] [ http:fieldName "Accept" ; http:fieldValue "text/turtle" ; http:hdrName <[…]w3.org/2008/http-header#accept> ] ) .
  • 14. Bringing it all together 1. Link headers to transparently inject data into an HTTP response without touching the body. 2. HTTP OPTIONS as a means of requesting communication options information. 3. HTTP Vocabulary in RDF for modeling HTTP communication. •  Real-world example: API for annotating YouTube videos with RDF: API In: YouTube video ID Out: text/turtle, application/rdf+xml
  • 15. Bringing it all together •  User agents can GET an RDF representation of a video. •  Generic string with meta information "this is a YouTube ID" as input by API definition. •  Generic output media types by API definition. •  RDF output document can be manually corrected via PUT, or DELETEed. $ curl -i -X GET -H "Accept: text/turtle" http:// api.example.org/youtube/videos/o4T9_MduMEQ API In: YouTube video ID Out: text/turtle, application/rdf+xml
  • 16. Bringing it all together •  Nice to document input constraints (YouTube ID). API •  Nice to document next steps based on the output. API •  Can use a combination of OPTIONS, Link headers, and HTTP Vocabulary in RDF to do this transparently. o  Send next steps (media controls) as Link headers. o  Document constraints for each request via OPTIONS.
  • 17. Bringing it all together $ curl -i -X OPTIONS http://api.example.org/youtube/videos HTTP/1.1 200 OK Content-Type: text/turtle; charset=utf-8 Link: <http://api.example.org/youtube/videos/{video_id}>; rel="related" Allow: GET, PUT, DELETE, HEAD, OPTIONS, PATCH Content-Length: xx _:req_1 a http:Request ; http:httpVersion "1.1" ; http:methodName "GET" ; … _:req_2 a http:Request ; http:httpVersion "1.1" ; http:methodName "PUT" ; … _:req_3 a http:Request ; http:httpVersion "1.1" ; http:methodName "DELETE" ; …
  • 18. Bringing it all together $ curl -i -X OPTIONS http://api.example.org/youtube/videos … Link: <http://api.example.org/youtube/videos/{video_id}>; rel="related" Allow: GET, HEAD, PUT, DELETE, OPTIONS, PATCH … _:req_1 a http:Request ; http:httpVersion "1.1" ; http:methodName "GET" ; http:mthd <http://www.w3.org/2008/http-methods#GET> ; exHttp:prefixPath "/youtube/" ; exHttp:suffixPath [ a api:uriTemplate ; a yt:videoid ; ] ; http:headers ( [ http:fieldName "Host" ; http:fieldValue "api.example.org" ; http:hdrName <http://www.w3.org/2008/http-header#host> ] ) .
  • 19. Bringing it all together _:req_1 a http:Request ; http:httpVersion "1.1" ; http:methodName "GET" ; http:mthd <http://www.w3.org/2008/http-methods#GET> ; exHttp:prefixPath "/youtube/" ; exHttp:suffixPath [ a api:uriTemplate ; a yt:videoid ; ] ; http:headers ( [ http:fieldName "Host" ; http:fieldValue "api.example.org" ; http:hdrName <http://www.w3.org/2008/http-header#host> ] ) . exHttp: Suggested extension of the HTTP Vocabulary in RDF for splitting http:abs_path (/foo/bar) in exHttp:prefixPath (/foo) and exHttp:suffixPath (/bar).
  • 20. Bringing it all together _:req_1 a http:Request ; http:httpVersion "1.1" ; http:methodName "GET" ; http:mthd <http://www.w3.org/2008/http-methods#GET> ; exHttp:prefixPath "/youtube/" ; exHttp:suffixPath [ a api:uriTemplate ; a yt:videoid ; ] ; http:headers ( [ http:fieldName "Host" ; http:fieldValue "api.example.org" ; http:hdrName <http://www.w3.org/2008/http-header#host> ] ) . api:uriTemplate: Borrowed from http://purl.org/linked-data/api/vocab# in order to model URI templates.
  • 21. Bringing it all together _:req_1 a http:Request ; http:httpVersion "1.1" ; http:methodName "GET" ; http:mthd <http://www.w3.org/2008/http-methods#GET> ; exHttp:prefixPath "/youtube/" ; exHttp:suffixPath [ a api:uriTemplate ; a yt:videoid ; ] ; http:headers ( [ http:fieldName "Host" ; http:fieldValue "api.example.org" ; http:hdrName <http://www.w3.org/2008/http-header#host> ] ) . yt:videoid: Defines the URI template to be a YouTube video ID (http://gdata.youtube.com/schemas/2007/videoid).
  • 22. Criticism •  The approach might encourage tight coupling. Evil? Depends. Might be OK if user agents evaluate their OPTIONS at runtime. •  HTTP Vocabulary in RDF might be too verbose, but it's a standard, and usually a bad standard is better than no standard. •  Total freedom (=chaos?) with regards to the RDF triples. Fair enough. However, extension relation types via URLs require human interaction as well.
  • 23. Thanks for your attention •  Thomas Steiner o  tomac@google.com o  @tomayac
  • 24. Image credits Lawn chair - http://www.cp-objekt.de/hundemoebel/Klappstuhl-Montana-st-426710-gr.jpg Poäng - http://www.ikea.com/au/en/catalog/products/10157948 Roy Fielding - http://upload.wikimedia.org/wikipedia/commons/thumb/c/cd/Roy_Fielding.jpg/450px-Roy_Fielding.jpg Direction sign - http://www.myparkingsign.com/img/lg/X/One-Direction-Arrow-Sign-X-W1-6L.gif Remote control - http://www.faqs.org/photo-dict/photofiles/list/824/1251remote_control.jpg LCD TV - http://www.slashgear.com/wp-content/uploads/2009/02/philips_nettv-480x370.jpg Fridge - http://modculture.typepad.com/photos/uncategorized/2008/06/13/smeg_mini.jpg Linked Data mug - http://www.w3.org/DesignIssues/diagrams/lod/480759174v0_350x350_Back.jpg Cloud - http://www.clipart.clipartist.net/openclipart/clipart/signs_and_symbols/weather/w_cloud_xxl.png Dr. Evil - http://upload.wikimedia.org/wikipedia/en/1/16/Drevil_million_dollars.jpg Fridge