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

Something Something Hypermedia APIs

Something Something Hypermedia APIs

Helior Colorado will elighten us with the concepts behind building Hypermedia APIs, which are really just an evolutionary approach to traditional RESTful Web Services. In this talk you'll better understand HTTP, URIs, and Hypertext, and the original intent behind these technologies. You'll also learn about such terms as HATEOAS, Hypermedia, media-types, self-descriptive APIs, affordances, out-of-band information, and more.

Video: http://www.youtube.com/watch?v=OdgVMrvfTHs

Avatar for Helior Colorado

Helior Colorado

January 09, 2014

More Decks by Helior Colorado

Other Decks in Technology

Transcript

  1. The success of the Web. • Largest platform in the

    world • Extendable • Future/backward compatible • High-scalability • Largely decoupled • Distributed
  2. 2001: A Web Odyssey Architectural Styles and! the Design of

    Network-based Software Architectures! by Roy Fielding http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm
  3. REST | rest | is an architectural style consisting of

    a coordinated set of constraints applied to components, connectors, and data elements, within a distributed hypermedia system.
  4. REST is… Defined by it’s constraints • Separation of concerns

    between client/server • Stateless • Cache-able • Uniform interface between components • Layered System • ….
  5. Resource | ˈrēˌsôrs | is a primitive object in the

    web, used in the definition of its fundamental elements.
  6. URI | yo͞o'är'ī | stands for Uniform Resource Identifier; is

    a string of characters used to identify a name of a web resource.
  7. HTTP | āCHˈtēˈtēˈpē | stands for Hypertext Transfer Protocol; it

    defines how messages are formatted and transmitted, and what actions Web servers and browsers should take in response to various commands. GET /events/2013-07-14/hypermedia-apis HTTP/1.1 HOST: www.helior.info
 Accept: text/html
  8. Richardson’s Maturity Model HTML HTTP URI Level 0 • One

    URI, one HTTP Method • XML-RPC and most of SOAP
  9. Richardson’s Maturity Model HTML HTTP Level 1 • Many URIs,

    one HTTP method • Most “RESTful” services that aren’t URI
  10. GET /events HTTP/1.1 HOST: www.helior.info Accept: application/json { "events": [

    { "id": "52", "name": "Foo Event", "date": "2013-07-19" }, { "id": "56", "name": "Bar Event", "date": "2013-09-28" }, { "id": "59", "name": "Baz Event", "date": "2014-01-08" } ] }
  11. Richardson’s Maturity Model HTML HTTP Level 2 • Many URIs,

    each supporting multiple HTTP methods URI
  12. Hypermedia | hīpərˈmēdēə | applied to various media-types, it is

    the logical extension of hypertext, which are documents that contain references to other documents.
  13. Hypermedia APIs | hīpərˈmēdēə āyˈpēˈīz | serve responses as hypermedia

    that manage application state. It is REST. The real REST defined in Roy Fielding’s dissertation.
  14. –Tim Berners-Lee, “Weaving the Web” “In an extreme view, the

    world can be seen as only connections, nothing else. We think of a dictionary as the repository of meaning, but it defines words only in terms of other words. I like the idea that a piece of information is really defined only by what it’s related to, and how it’s related.”
  15. Transitioning from REST to Hypermedia is like moving the focus

    away from resources and into the action that you want to take place.
  16. Out-of-band | outˌəvˈband | implied processing instructions that are not

    included within the response message of an API server. ! When they should be.
  17. Home List of products Product 2 Add product 2 to

    cart View cart Checkout Remove from cart Change quantity Managing Application State
  18. Affordance | əˈfôrd-əns | is the current representation of links

    and controls that reflect the context of a given state, such that the user obtains choices and can select actions.
  19. –Marc Andreessen, “proposed new tag: IMG” “This is required functionality

    for X Mosaic; we have this working, and we’ll at least be using it internally. I’m certainly open to suggestions as to how this should be handled within HTML; if you have a better idea than what I’m presenting now, please let me know. I know this is hazy wrt image format, but I don’t see an alternative than to just say “let the browser do what it can” and wait for the perfect solution to come along (MIME, someday, maybe).”
  20. Describe your API through new/existing media- types, and/or define relation

    names or markup that extend standard media-types.
  21. Don't define fixed resource names or hierarchies; servers should instruct

    the client to construct URIs within link relations.
  22. State transition must be driven by the client selection of

    server-provided choices, or affordances.
  23. –Steve Klabnik, “Designing Hypermedia APIs” “Hypermedia promotes scalability, allows resilience

    towards future changes, and promotes decoupling and encapsulation, with all the benefits those things bring.”