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

Hypermedia For Y'All

apotonick
December 27, 2011
220

Hypermedia For Y'All

The presentation I gave at the RubyConf Brazil 2011.

apotonick

December 27, 2011
Tweet

Transcript

  1. Roar! componentized app ...still pretty URLs real REST services with

    GET, PUT, POST, DELETE no HTML! embedded hypermedia REST
  2. Roar! GET http://orders/1 id: 1 created_at: August 30 to proceed:

    http://orders/1/pay to update: http://orders/1
  3. Roar! {order: { id : 1 created_at: August 31 links

    : [ {rel : proceed href: http://orders/1/pay} {rel : self href: http://orders/1} ] } Hypermedia & JSON
  4. Roar! POST http://orders ------------------------ client_id: 42 id : 1 client_id:

    42 beers : [] links : [ {rel : self href: http://orders/1} {rel : beers href: http://orders/1/be ]
  5. Roar! Single entry point – the one and only URL

    we know POST http://orders ------------------------ client_id: 42
  6. Roar! id : 1 client_id: 42 beers : [] links

    : [ {rel: self href: http://orders/1} {rel: beers href: http://orders/1/beers} ] self link – pointing to current resource
  7. Roar! id : 1 client_id: 42 beers : [] links

    : [ {rel: self href: http://orders/1} {rel: beers href: http://orders/1/beers} ] beers link – items placed in order
  8. Roar! GET http://orders/1 id : 1 client_id: 42 beers :

    [] links : [ {rel : self href: http://orders/1} {rel : beers href: http://orders/1/be ]
  9. Roar! GET http://orders/1/beers beers: [] links: [ {rel : self

    href: http://orders/1/be {rel : order href: http://orders/1}
  10. Roar! POST http://orders/1/beers ------------------------ {name: Anchor Steam} Created! It's at

    http://orders/1/beers/anchors team Created! It's at http://orders/1/beers/anchors team
  11. Roar! GET http://orders/1 id : 1 client_id: 42 beers: [

    {name: Anchor Steam links: [ {rel : self href: http://orders/1/ ]} ],
  12. Roar! id : 1 client_id: 42 beers: [ {name: Anchor

    Steam links: [ {rel : self href: http://orders/1/beers/anchorsteam} ]} ], links: [ {rel: self href: http://orders/1} {rel: beers href: http://orders/1/beers} ] +
  13. Roar! id : 1 client_id: 42 beers: [ {name: Anchor

    Steam links: [ {rel : self href: http://orders/1/beers/anchorsteam} ]} ], links: [ {rel: self href: http://orders/1} {rel: beers href: http://orders/1/beers} ] +
  14. Roar! GET http://orders/1 id : 1 client_id: 42 beers :

    [] links : [ {rel : self href: http://orders/1} {rel : beers href: http://orders/1/be ]
  15. Roar! GET http://orders/1 id : 1 client_id: 42 beers :

    [] links : [ {rel : self href: http://orders/1} {rel : beers href: http://orders/1/be ]
  16. 58 Roar! class Beer include Roar::Representer::JSON property :name property :id

    link :self do beer_url(id) end Plain properties Hypermedia support yo
  17. 59 Roar! Beer.new(:id => 1, :name => "NickBrew").to_json from Roar

    {"beer":{ "id" : 1, "name" : "NickBrew", "links": [{"rel":"self","href":"http://beers/1"}]}}
  18. 60 Roar! brew = Beer.from_json '{"beer":{ "id" : 1, "name"

    : "NickBrew"}}' from Roar brew.name #=> „NickBrew“
  19. 61 Roar! class Beer include Roar::Representer::XML ... jaja brew.to_xml <beer>

    <id>1</id> <name>NickBrew</name> <link rel="self" href="http://beers/1"/> </beer>
  20. 64 Roar! brew.new(:name => „SKOL“) brew.new(:name => „SKOL“) brew.extend Feature::HTTPVerbs

    brew.new(:name => „SKOL“) brew.extend Feature::HTTPVerbs brew.post!(„http://beers“) brew.new(:name => „SKOL“) brew.extend Feature::HTTPVerbs brew.post!(„http://beers“) puts „I'm at“ + brew.links[:self] #=> „http://beers/99“