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

Building well-defined APIs part 1: Proper HTTP

Building well-defined APIs part 1: Proper HTTP

Short intro to Ruby port of Webmachine.

Nikica Jokić

December 23, 2014
Tweet

More Decks by Nikica Jokić

Other Decks in Technology

Transcript

  1. • simple syntax, semantics up to you • easy to

    build crappy, bad-behaving APIs HTTP is deceptively simple
  2. • simple syntax, semantics up to you • easy to

    build crappy, bad-behaving APIs • use error status codes HTTP is deceptively simple
  3. • simple syntax, semantics up to you • easy to

    build crappy, bad-behaving APIs • use error status codes • respect content-types (accept headers) HTTP is deceptively simple
  4. • simple syntax, semantics up to you • easy to

    build crappy, bad-behaving APIs • use error status codes • respect content-types (accept headers) • handle resource migration and locations HTTP is deceptively simple
  5. • Not a framework - a toolkit • Implements the

    HTTP protocol as a state-machine Webmachine (1/2)
  6. • Not a framework - a toolkit • Implements the

    HTTP protocol as a state-machine Webmachine (1/2)
  7. • Not a framework - a toolkit • Implements the

    HTTP protocol as a state-machine Webmachine (1/2)
  8. • Not a framework - a toolkit • Implements the

    HTTP protocol as a state-machine • Several implementations: Webmachine (1/2)
  9. • Not a framework - a toolkit • Implements the

    HTTP protocol as a state-machine • Several implementations: • Webmachine (1st Erlang, then Ruby) Webmachine (1/2)
  10. • Not a framework - a toolkit • Implements the

    HTTP protocol as a state-machine • Several implementations: • Webmachine (1st Erlang, then Ruby) • Liberator (Clojure) Webmachine (1/2)
  11. • Not a framework - a toolkit • Implements the

    HTTP protocol as a state-machine • Several implementations: • Webmachine (1st Erlang, then Ruby) • Liberator (Clojure) • others? Webmachine (1/2)
  12. • Declarative • Works by describing facts about the resource

    Webmachine (2/2) get '/hello/:name' do "Hello #{params[:name]}!" end
  13. • Declarative • Works by describing facts about the resource

    Webmachine (2/2) get '/hello/:name' do "Hello #{params[:name]}!" end def resource_exists? resource end
  14. • Declarative • Works by describing facts about the resource

    Webmachine (2/2) get '/hello/:name' do "Hello #{params[:name]}!" end def resource_exists? resource end • known-method? / method-allowed ? • known-media-type? / media-type-available? • allowed? / authorised? • exists? / existed? • moved-temporarily? / moved-permanently?