I got 99 problems, but ReST ain't one

Adrian Cole
Adrian Colezipkin guy at Pivotal
> GET /problems/MONEY HTTP/1.1   I	 GOT	 99
                                 PROBLEMS
> Host: localhost
> Accept: */*

< HTTP/1.1 200 OK




> GET /problems/POWER HTTP/1.1
> Host: localhost
                                 BUT	 REST
                                 AINT	 ONE
> Accept: */*

< HTTP/1.1 200 OK



> GET /problems/REST HTTP/1.1
> Host: localhost
> Accept: */*
                                 @adrianfcole
< HTTP/1.1 404 Not Found
PROBLEMS
 ➡Why API
 ➡ReST vs other HTTP APIs?
 ➡Design Patterns vs Real APIs
WHO	 IS	 THIS	 GUY?
๏ @adrianfcole

๏ architect CloudHub at MuleSoft

๏founder jclouds
THANKS
  ★     api-craft
  ★     mattstep
  ★   gtcampbell
  ★       mulies
WHY	 WE	 API

          photo copyright 2005 Sony Pictures
COLLABORATE
GROW	 
ECOSYSTEM
AND	 
INNOVATE
HOW	 
TO	  ReST SOAP
API
HOW	 
TO	  ReST WS-*
API
HOW	 
TO	  ReST ReST   ish

API
HOW	 
TO	  not-soap   HATEOAS
REST
To	 the	 
        Level 0:
        Level 1:
                   Swamp of POX
                   Resources
glory	  Level 2:
        Level 3:
                   Verbs
                   Hypermedia

of	 
REST
> POST /api HTTP/1.1
                         > <SOAP-ENV:Envelope ...>
                           <SOAP-ENV:Body>
                             <m:getAvailableDataSources xmlns:m="




Swamp	 
                               <group xsi:type="xsd:string">ArcWe
                               <service xsi:type="xsd:string">Map
                               <token xsi:type="xsd:string">MyTok
                             </m:getAvailableDataSources>




of	 POX
                           </SOAP-ENV:Body>
                         </SOAP-ENV:Envelope>

                         < HTTP/1.1 200 OK
                         < <?xml version="1.0" encoding="UTF-8"?>
                         <soap:Envelope ...>
                           <soap:Body>
                             <n:getAvailableDataSourcesResponse x
                               <Result href="#id0"/>
                             </n:getAvailableDataSourcesResponse>
All things go over the       <id0 id="id0" soapenc:root="0" xsi:t
                         soapenc:arrayType="ns5:DataSource[21]">
same endpoint as XML           <i href="#id1"/>
                         --snip--
RESOURCES
> GET https://ec2.amazonaws.com/?Action=DeleteVolume&VolumeId=vol-4282672b HTTP/1.1

< HTTP/1.1 200 OK

<DeleteVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2012-08-15/">
  <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
  <return>true</return>
</DeleteVolumeResponse>

   --snip--

                         Many URIs, same HTTP method
                          Side-effects are API-specific
VERBS
    > HEAD https://mybucket.s3.amazonaws.com/ HTTP/1.1

    < HTTP/1.1 200 OK




 HTTP verbs mean more than CRUD
    Status codes are meaningful
HYPERMEDIA
    > GET https://vcloud/api/v1.0/catalogItem/1c01defe-1111-42ac-a50f-9dd4e03546
    > Accept: application/vnd.vmware.vcloud.catalogItem+xml

    < HTTP/1.1 200 OK
    < Content-Type: application/vnd.vmware.vcloud.catalogItem+xml;version=1.0

    <CatalogItem xmlns="http://www.vmware.com/vcloud/v1" name="mycatalog" type="
                 href="https://vcloud/api/v1.0/catalogItem/1c01defe-1111-42ac-a5
        <Link rel="up" type="application/vnd.vmware.vcloud.catalog+xml"
              href="https://vcloud/api/v1.0/catalog/7f192dfe-00d1-42f2-9f76-9360
        <Link rel="edit" type="application/vnd.vmware.vcloud.catalogItem+xml"
              href="https://vcloud/api/v1.0/catalogItem/1c01defe-1111-42ac-a50f-
        <Link rel="remove"
             href="https://vcloud/api/v1.0/catalogItem/1c01defe-1111-42ac-a50f-9
    --snip--




Discoverability, Self-documenting
What	 makes	 
it	 HYPER?
      ➡Base Type
      ➡Links
abort

                                                  add

                                                  alternate

                                                  disk:attach




    TRANSITIONS                                   edit

                                                  remove

                                                  task




All	 transitions	 are	 discoverable	 via	 links
CONTENT	 
NEGOTIATION
 ➡   Client supplies representation in
    Accept header
 ➡On change, update mediatype
    name or annotate via ;version=N.N
 ➡On overhaul, bump global version
 Accept: application/vnd.VENDOR.PRODUCT.RESOURCE+xml
Representing	 
HyperMedia
    Extend Atom
    Opaque + Link Headers
    HAL
    ...
EXTEND	 ATOM
      Vendor Type, Link elements
      < HTTP/1.1 200 OK
      < Content-Type: application/vnd.vmware.vcloud.catalogItem+xml;version=1.0

      <CatalogItem xmlns="http://www.vmware.com/vcloud/v1" name="mycatalog" type="
                   href="https://vcloud/api/v1.0/catalogItem/1c01defe-1111-42ac-a5
          <Link rel="up" type="application/vnd.vmware.vcloud.catalog+xml"
                href="https://vcloud/api/v1.0/catalog/7f192dfe-00d1-42f2-9f76-9360
          <Link rel="edit" type="application/vnd.vmware.vcloud.catalogItem+xml"
                href="https://vcloud/api/v1.0/catalogItem/1c01defe-1111-42ac-a50f-
          <Link rel="remove"
               href="https://vcloud/api/v1.0/catalogItem/1c01defe-1111-42ac-a50f-9
      --snip--



domain-specific types
inherits link semantics from Atom
Link	 Headers
      Opaque Type, Link elements
      < HTTP/1.1 200 OK
      < Content-Type: image/jpeg
      Link: </images/foo.png>; rel="alternate"; type=”image/png”

      010101010101010101
      --snip--




supports binary types
facilitates intermediaries
Hypertext	 Application	 Language
     Mix-in hypermedia controls into base type
     embed resources for efficiency
     < HTTP/1.1 200 OK
     < Content-Type: application/hal+json

     {
         _links: {
            self: {
              href: '/example',
            }
         },
         _embedded: {},
         name: 'foo',

     --snip--



domain-specific type agnostic
ELEGENT
clients always
know transitions

self-documenting
                   LETS	 USE
and discoverable

version at
                   HATEOAS
media-type
granularity
Perceived	 
Complexity?
Level	 2	 
optimizes	 
for Coarse Grained Versions
    CRUD++
    Limited Representations
    Today’s Tools
    Simplicity over Elegance
IS	 IT	 ALL	 
JUST	 
PRICKLES	 
&	 GOO?
can	 we	 have	 both?
There	       Domain	 Style
           Base	 Format
is	 no	      State	 Transfer
Level2          App	 Flow
 Design
            plus stuff like errors
REST	 Design	 
tools
       ➡Apiary
       ➡Swagger
       ➡iodocs
GOOD	 API	 DESIGNERS	 
UNDERSTAND
 how it is used, and who will use it

 importance of iterations and feedback

 impacts to design beyond development

 there’s no golden hammer   (not even mongo)
TWITTER	 IS	 NOT	 
HATEOAS
         REST
         SEARCH
         STREAM
AWS	 IS	 NOT	 REST	 
AWS	 IS	 GOOD
api designed to parse quickly

simple extension (add new key)

consistent security model

bulk ops
WebSockets	 	 
ain’t	 even
HTTP! Handshake is HTTPish
      Discoverable like ReST

      Full-Duplex
      Uncode or Binary Messages
      TCP Protocol
GOOD	 REST	 APIs
Are consciously designed

Version at the right scope

Don’t leak implementation details

Use auth models relevant to consumer

Are well documented with examples
What	 now?
 ➡join api-craft
 ➡read The REST API Design Handbook
 ➡read Building Hypermedia APIs...
 ➡socialize your ideas
       Thank	 you!
1 of 35

More Related Content

What's hot(20)

REST APIs with SpringREST APIs with Spring
REST APIs with Spring
Joshua Long25.6K views
Spring boot introductionSpring boot introduction
Spring boot introduction
Rasheed Waraich7.7K views
Restful api designRestful api design
Restful api design
Mizan Riqzia1.5K views
OAuth2 - IntroductionOAuth2 - Introduction
OAuth2 - Introduction
Knoldus Inc.6.3K views
Xke spring bootXke spring boot
Xke spring boot
sourabh aggarwal1.3K views
SvelteSvelte
Svelte
University of Moratuwa, Katubedda, Sri Lanka136 views
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
Santosh Kumar Kar19.4K views
Introduction to OpenID Connect Introduction to OpenID Connect
Introduction to OpenID Connect
Nat Sakimura18.3K views
Understanding RESTUnderstanding REST
Understanding REST
Nitin Pande6.4K views
Design Beautiful REST + JSON APIsDesign Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIs
Stormpath225.9K views
Demystifying OAuth 2.0Demystifying OAuth 2.0
Demystifying OAuth 2.0
Karl McGuinness7.5K views
Sql Injection Myths and FallaciesSql Injection Myths and Fallacies
Sql Injection Myths and Fallacies
Karwin Software Solutions LLC115.2K views
Exception handlingException handling
Exception handling
Anna Pietras941 views
OpenTelemetry For DevelopersOpenTelemetry For Developers
OpenTelemetry For Developers
Kevin Brockhoff2.1K views

Viewers also liked(20)

A New Model for TestingA New Model for Testing
A New Model for Testing
SQALab1.4K views
Psychology and testingPsychology and testing
Psychology and testing
SQALab735 views

Similar to I got 99 problems, but ReST ain't one(20)

More from Adrian Cole(6)

HTTP/2 What's inside and WhyHTTP/2 What's inside and Why
HTTP/2 What's inside and Why
Adrian Cole4.5K views
Efficient HTTP ApisEfficient HTTP Apis
Efficient HTTP Apis
Adrian Cole5.6K views
jclouds overviewjclouds overview
jclouds overview
Adrian Cole1.1K views
Living on the edgeLiving on the edge
Living on the edge
Adrian Cole2.8K views

Recently uploaded(20)

Green Leaf Consulting: Capabilities DeckGreen Leaf Consulting: Capabilities Deck
Green Leaf Consulting: Capabilities Deck
GreenLeafConsulting170 views
ChatGPT and AI for Web DevelopersChatGPT and AI for Web Developers
ChatGPT and AI for Web Developers
Maximiliano Firtman152 views
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)
CSUC - Consorci de Serveis Universitaris de Catalunya51 views
Java Platform Approach 1.0 - Picnic MeetupJava Platform Approach 1.0 - Picnic Meetup
Java Platform Approach 1.0 - Picnic Meetup
Rick Ossendrijver23 views
METHOD AND SYSTEM FOR PREDICTING OPTIMAL LOAD FOR WHICH THE YIELD IS MAXIMUM ...METHOD AND SYSTEM FOR PREDICTING OPTIMAL LOAD FOR WHICH THE YIELD IS MAXIMUM ...
METHOD AND SYSTEM FOR PREDICTING OPTIMAL LOAD FOR WHICH THE YIELD IS MAXIMUM ...
Prity Khastgir IPR Strategic India Patent Attorney Amplify Innovation23 views

I got 99 problems, but ReST ain't one

  • 1. > GET /problems/MONEY HTTP/1.1 I GOT 99 PROBLEMS > Host: localhost > Accept: */* < HTTP/1.1 200 OK > GET /problems/POWER HTTP/1.1 > Host: localhost BUT REST AINT ONE > Accept: */* < HTTP/1.1 200 OK > GET /problems/REST HTTP/1.1 > Host: localhost > Accept: */* @adrianfcole < HTTP/1.1 404 Not Found
  • 2. PROBLEMS ➡Why API ➡ReST vs other HTTP APIs? ➡Design Patterns vs Real APIs
  • 3. WHO IS THIS GUY? ๏ @adrianfcole ๏ architect CloudHub at MuleSoft ๏founder jclouds
  • 4. THANKS ★ api-craft ★ mattstep ★ gtcampbell ★ mulies
  • 5. WHY WE API photo copyright 2005 Sony Pictures
  • 7. HOW TO ReST SOAP API
  • 8. HOW TO ReST WS-* API
  • 9. HOW TO ReST ReST ish API
  • 10. HOW TO not-soap HATEOAS REST
  • 11. To the Level 0: Level 1: Swamp of POX Resources glory Level 2: Level 3: Verbs Hypermedia of REST
  • 12. > POST /api HTTP/1.1 > <SOAP-ENV:Envelope ...> <SOAP-ENV:Body> <m:getAvailableDataSources xmlns:m=" Swamp <group xsi:type="xsd:string">ArcWe <service xsi:type="xsd:string">Map <token xsi:type="xsd:string">MyTok </m:getAvailableDataSources> of POX </SOAP-ENV:Body> </SOAP-ENV:Envelope> < HTTP/1.1 200 OK < <?xml version="1.0" encoding="UTF-8"?> <soap:Envelope ...> <soap:Body> <n:getAvailableDataSourcesResponse x <Result href="#id0"/> </n:getAvailableDataSourcesResponse> All things go over the <id0 id="id0" soapenc:root="0" xsi:t soapenc:arrayType="ns5:DataSource[21]"> same endpoint as XML <i href="#id1"/> --snip--
  • 13. RESOURCES > GET https://ec2.amazonaws.com/?Action=DeleteVolume&VolumeId=vol-4282672b HTTP/1.1 < HTTP/1.1 200 OK <DeleteVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2012-08-15/"> <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId> <return>true</return> </DeleteVolumeResponse> --snip-- Many URIs, same HTTP method Side-effects are API-specific
  • 14. VERBS > HEAD https://mybucket.s3.amazonaws.com/ HTTP/1.1 < HTTP/1.1 200 OK HTTP verbs mean more than CRUD Status codes are meaningful
  • 15. HYPERMEDIA > GET https://vcloud/api/v1.0/catalogItem/1c01defe-1111-42ac-a50f-9dd4e03546 > Accept: application/vnd.vmware.vcloud.catalogItem+xml < HTTP/1.1 200 OK < Content-Type: application/vnd.vmware.vcloud.catalogItem+xml;version=1.0 <CatalogItem xmlns="http://www.vmware.com/vcloud/v1" name="mycatalog" type=" href="https://vcloud/api/v1.0/catalogItem/1c01defe-1111-42ac-a5 <Link rel="up" type="application/vnd.vmware.vcloud.catalog+xml" href="https://vcloud/api/v1.0/catalog/7f192dfe-00d1-42f2-9f76-9360 <Link rel="edit" type="application/vnd.vmware.vcloud.catalogItem+xml" href="https://vcloud/api/v1.0/catalogItem/1c01defe-1111-42ac-a50f- <Link rel="remove" href="https://vcloud/api/v1.0/catalogItem/1c01defe-1111-42ac-a50f-9 --snip-- Discoverability, Self-documenting
  • 16. What makes it HYPER? ➡Base Type ➡Links
  • 17. abort add alternate disk:attach TRANSITIONS edit remove task All transitions are discoverable via links
  • 18. CONTENT NEGOTIATION ➡ Client supplies representation in Accept header ➡On change, update mediatype name or annotate via ;version=N.N ➡On overhaul, bump global version Accept: application/vnd.VENDOR.PRODUCT.RESOURCE+xml
  • 19. Representing HyperMedia Extend Atom Opaque + Link Headers HAL ...
  • 20. EXTEND ATOM Vendor Type, Link elements < HTTP/1.1 200 OK < Content-Type: application/vnd.vmware.vcloud.catalogItem+xml;version=1.0 <CatalogItem xmlns="http://www.vmware.com/vcloud/v1" name="mycatalog" type=" href="https://vcloud/api/v1.0/catalogItem/1c01defe-1111-42ac-a5 <Link rel="up" type="application/vnd.vmware.vcloud.catalog+xml" href="https://vcloud/api/v1.0/catalog/7f192dfe-00d1-42f2-9f76-9360 <Link rel="edit" type="application/vnd.vmware.vcloud.catalogItem+xml" href="https://vcloud/api/v1.0/catalogItem/1c01defe-1111-42ac-a50f- <Link rel="remove" href="https://vcloud/api/v1.0/catalogItem/1c01defe-1111-42ac-a50f-9 --snip-- domain-specific types inherits link semantics from Atom
  • 21. Link Headers Opaque Type, Link elements < HTTP/1.1 200 OK < Content-Type: image/jpeg Link: </images/foo.png>; rel="alternate"; type=”image/png” 010101010101010101 --snip-- supports binary types facilitates intermediaries
  • 22. Hypertext Application Language Mix-in hypermedia controls into base type embed resources for efficiency < HTTP/1.1 200 OK < Content-Type: application/hal+json { _links: { self: { href: '/example', } }, _embedded: {}, name: 'foo', --snip-- domain-specific type agnostic
  • 23. ELEGENT clients always know transitions self-documenting LETS USE and discoverable version at HATEOAS media-type granularity
  • 25. Level 2 optimizes for Coarse Grained Versions CRUD++ Limited Representations Today’s Tools Simplicity over Elegance
  • 26. IS IT ALL JUST PRICKLES & GOO?
  • 27. can we have both?
  • 28. There Domain Style Base Format is no State Transfer Level2 App Flow Design plus stuff like errors
  • 29. REST Design tools ➡Apiary ➡Swagger ➡iodocs
  • 30. GOOD API DESIGNERS UNDERSTAND how it is used, and who will use it importance of iterations and feedback impacts to design beyond development there’s no golden hammer (not even mongo)
  • 31. TWITTER IS NOT HATEOAS REST SEARCH STREAM
  • 32. AWS IS NOT REST AWS IS GOOD api designed to parse quickly simple extension (add new key) consistent security model bulk ops
  • 33. WebSockets ain’t even HTTP! Handshake is HTTPish Discoverable like ReST Full-Duplex Uncode or Binary Messages TCP Protocol
  • 34. GOOD REST APIs Are consciously designed Version at the right scope Don’t leak implementation details Use auth models relevant to consumer Are well documented with examples
  • 35. What now? ➡join api-craft ➡read The REST API Design Handbook ➡read Building Hypermedia APIs... ➡socialize your ideas Thank you!

Editor's Notes

  1. \n
  2. we need to define what we are talking about, and then evaluate patterns\n
  3. \n
  4. \n
  5. Now that we are here, we underscore motivations to even bother with.\n
  6. A Web API Study: Hurwitz;\n leads to integration -&gt; stronger ecosystem -&gt; more value\n &gt; devices and applications in the ecosystem\n\n
  7. At first glance, we might think how to present an api is rest vs soap\n
  8. it might really be the aspects of WS-* that would make such a decision, such as WS-Security, AtomicTransaction, ReliableMessaging\n
  9. Say we chose, ReST.. the thing is that ReST means a lot to many people\n
  10. ends up being something between soap and hypertext driven\n
  11. Leonard Richardson circa 2008 Maturity Model\n
  12. Easiest example of POX is tunneling commands over a single http request/response paradigm\n
  13. many uris, but a single invocation method. operations might be encoded in parameters, and resource might be mixed in with them\n
  14. HEAD is metadata; PATCH is for update; PUT is replace; POST -&gt; RPC/create\natomicity underpins idempotence; by spec POST can affect multiple resources, but most others (except notably trace,options) only apply to the resource identified by the href\n
  15. \n
  16. \n
  17. HATEOAS is basically a state machine. Your responsibility is to not attempt any transition undefined in links\n
  18. New resources types can be added without breaking client, as can new fields/links\nabove pattern recommended by: Dan Feist\n\nOther option you can use is link with profile relation.\n
  19. There are other ways, too...\nxlink can decorate in namespace of xml, but doesn&amp;#x2019;t expose representations\ncollection+json is an interesting approach for managing collections (includes its own data format)\n
  20. \n
  21. ex. cache intermediaries http://tools.ietf.org/html/draft-nottingham-linked-cache-inv-03\n
  22. define domain-specific type using type link parameter, or via custom rel or profile link (preferred)\nhttp://tools.ietf.org/id/draft-kelly-json-hal\nalso supports templated urls such as queries\n
  23. \n
  24. sometimes domain models are well defined, so the added value may be lost on the user\n
  25. Leonard Richardson circa 2008 Maturity Model\n
  26. Prickles &amp; Goo: Alan Watts Trey Parker Matt Stone\nIs culture behind adoption of a particular rest approach? Even if the approach is correct, can you persuade devs to adopt something they don&amp;#x2019;t want?\n
  27. we are probably at various intervals on the same plane. more detail == overly complex. not enough == naive.\n
  28. Amundsen, Mike (2011-11-22). Building Hypermedia APIs with HTML5 and Node (p. 20). OReilly Media - A. Kindle Edition. \n
  29. http://apiary.io/ &lt; markdown extension describes behavior, generates mock and tests it\nhttp://swagger.wordnik.com/ &lt;- json describes resource, apis, models, generates many clients\nhttps://github.com/mashery/iodocs &lt;- json describes service, apis, creates javascript client\n
  30. database details such as pagination, etc\n\ntransition to a design that isn&amp;#x2019;t rest (aws)\n
  31. original has been around since 2008, latest update mainly addressed oauth and rate limiting changes; thanks Greg Campbell for insight; api is versioned as 1.1, but includes 3 distinct apis\naside: search can be modeled in HATEOAS, where POST is creation of search results, HEAD returns lifespan, etc\n\n
  32. Many amazon web services do not even follow type 2 classifications, yet they are widely adopted, and successful.. why is that? why do they not use rest?\n\ngurupa is the amazon http server, which is tuned for query parsing. language for extending it is simple (add a key), so parsing it to verify signature is just sort the keys and sign it.\n\nbulk ops like s3 multi-delete help deal with very large problems.\n
  33. Ex. ELB you have to use TCP/SSL as this is not a HTTP compatible protocol\nconsider impact for example lack of origin IP address, sticky session\nnew set of gateway products will emerge to support WebSockets\n
  34. database details such as pagination, etc\n
  35. \n