Building a REST API


         Jim Barritt
        Marc Johnson
Building a REST API


         Jim Barritt
        Marc Johnson
hypermedia
Building a REST API


         Jim Barritt
        Marc Johnson
Rise of the API
What do we want?
What do we want?
• A platform for innovation
What do we want?
• A platform for innovation
• Long term stability
What do we want?
• A platform for innovation
• Long term stability
• Available and performant
What do we want?
• A platform for innovation
• Long term stability
• Available and performant
• Uniform, ubiquitous access
What do we want?
• A platform for innovation
• Long term stability
• Available and performant
• Uniform, ubiquitous access
• Low cost of development
What do we want?
• A platform for innovation
• Long term stability
• Available and performant
• Uniform, ubiquitous access
• Low cost of development
• Evolvable
What do we want?
• A platform for innovation
• Long term stability
• Available and performant
• Uniform, ubiquitous access
• Low cost of development
• Evolvable
• Mashable
How do we get it?
hypermedia
hypermedia



<user>
  <userName>bob@foo.com</userName>
  <status>Active</status>
</user>                              ?
hypermedia



<user>
  <userName>bob@foo.com</userName>
  <status>Active</status>
</user> rel=”entitlements” href=”...” />
  <link
</user>
                                           ?
hypermedia



<user>
  <userName>bob@foo.com</userName>
  <status>Active</status>
</user> rel=”entitlements” href=”...” />
  <entitlements href=”http://...” />
  <link
</user>
                                           ?
hypermedia
hypermedia



http://api.com/users/{userId}/profile
hypermedia


                         NO!
http://api.com/users/{userId}/profile
hypermedia


           USER

   jimb@thoughtworks.com
                             NO!
http://api.com/users/{userId}/profile
       profile         GET : http://...

                               PROFILE
resources
                           USERS




                    POST


        USER

jimb@thoughtworks.com
?                                                  ?
                   @duncancragg




                                          @jimwebber
    @mnot




                                                         ?
?                      @fielding


                                        @mamund

        @ianrobinson
                               http://tools.ietf.org/wg/httpbis/
                http://tech.groups.yahoo.com/group/rest-discuss/
What we chose....
application/xml
       vs
application/json
application/vnd.foo+xml
          vs
    application/xml
application/atom+xml

<link rel="profile" href="..." />



              USER

      jimb@thoughtworks.com


            profile           GET : http://...

                                    PROFILE
Describing things....
Describing things....

<user>
  <userName>jimb@thoughtworks.com</userName>
  <status>Active</status>
  <link rel="profile" href="..." />
  <link rel="entitlements" href="..." />
  <link rel="licences" href="..." />
</user>
Finding things....
Finding things....

GET: /users?userName=jimb@thoughtworks.com
Finding things....

GET: /users?userName=jimb@thoughtworks.com

vs

POST: /users HTTP/1.1
<search>
   <userName>jimb@thoughtworks.com</userName>
</search>
Many things....
Many things....
POST: /users HTTP/1.1
<search>
  <country>UK</country>
</search>
Many things....
POST: /users HTTP/1.1
<search>
  <country>UK</country>
</search>
HTTP/1.1 200 OK
Content-Type: application/xml
<list of=”user”>
  <link rel="user" href="..." />
  <link rel="user" href="..." />
  <link rel="user" href="..." />
</site>
One thing....
One thing....


POST: /users HTTP/1.1
<search>
   <userName>jimb@thoughtworks.com</userName>
</search>
One thing....


POST: /users HTTP/1.1
<search>
   <userName>jimb@thoughtworks.com</userName>
</search>

HTTP/1.1 200 OK
Location: /users/234234
POST: /users HTTP/1.1

             vs

POST: /users/search HTTP/1.1
Linked resources...
SITE
                 USERS



                           ENTITLEMENT

                    USER




       PROFILE

                            CREDIT
                            BALANCE
<form method=”POST”
action=”http://...”>

         vs

  POST: http://...
Walkthrough...
GET: /sites/jkshop HTTP/1.1
GET: /sites/jkshop HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/xml
<site>
  <siteName>jkshop</siteName>
  <link rel="users" href="..." />
  <link rel="authentication" href="..." />
</site>
GET: /sites/jkshop HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/xml
<site>
  <siteName>jkshop</siteName>
  <link rel="users" href="..." />
  <link rel="authentication" href="..." />
</site>
POST:/sites/jskshop/users HTTP/1.1
<search>
    <userName>jimb@thoughtworks.com</userName>
</search>
POST:/sites/jskshop/users HTTP/1.1
<search>
    <userName>jimb@thoughtworks.com</userName>
</search>
HTTP/1.1 303 See Other
Location: /users/234234
POST:/sites/jskshop/users HTTP/1.1
<search>
    <userName>jimb@thoughtworks.com</userName>
</search>
HTTP/1.1 303 See Other
Location: /users/234234

GET:/users/234234 HTTP/1.1
POST:/sites/jskshop/users HTTP/1.1
<search>
    <userName>jimb@thoughtworks.com</userName>
</search>
HTTP/1.1 303 See Other
Location: /users/234234

GET:/users/234234 HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/xml
<user>
  <userName>jimb@thoughtworks.com</userName>
  <status>Active</status>
  <userIdentifier>...</userIdentifier>
  <link rel="profile" href="..." />
  <link rel="entitlements" href="..." />
  <link rel="licences" href="..." />
</user>
POST:/sites/jskshop/users HTTP/1.1
<search>
    <userName>jimb@thoughtworks.com</userName>
</search>
HTTP/1.1 303 See Other
Location: /users/234234

GET:/users/234234 HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/xml
<user>
  <userName>jimb@thoughtworks.com</userName>
  <status>Active</status>
  <userIdentifier>...</userIdentifier>
  <link rel="profile" href="..." />
  <link rel="entitlements" href="..." />
  <link rel="licences" href="..." />
</user>
POST: /users/234234/entitlements HTTP/1.1
<search>
  <onDate>23-01-2012</onDate>
</search>
POST: /users/234234/entitlements HTTP/1.1
<search>
  <onDate>23-01-2012</onDate>
</search>
HTTP/1.1 303 See Other
Location: /entitlements/234234/23-01-2012
POST: /users/234234/entitlements HTTP/1.1
<search>
  <onDate>23-01-2012</onDate>
</search>
HTTP/1.1 303 See Other
Location: /entitlements/234234/23-01-2012

GET: /entitlements/234234/23-01-2012 HTTP/1.1
POST: /users/234234/entitlements HTTP/1.1
<search>
  <onDate>23-01-2012</onDate>
</search>
HTTP/1.1 303 See Other
Location: /entitlements/234234/23-01-2012

GET: /entitlements/234234/23-01-2012 HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/xml
<entitlement>
  <entitledTo>
    <product name="FRUIT">
      <productItem name="APPLES" />
    </product>
    <link rel="licence" href="..." />
    <link rel="seat" href="..." />
    <link rel="credits" href="..." />
  </entitledTo>
</entitlement>
POST: /users/234234/entitlements HTTP/1.1
<search>
  <onDate>23-01-2012</onDate>
</search>
HTTP/1.1 303 See Other
Location: /entitlements/234234/23-01-2012

GET: /entitlements/234234/23-01-2012 HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/xml
<entitlement>
  <entitledTo>
    <product name="FRUIT">
      <productItem name="APPLES" />
    </product>
    <link rel="licence" href="..." />
    <link rel="seat" href="..." />
    <link rel="credits" href="..." />
  </entitledTo>
</entitlement>
GET: /credits/234234/23-01-2012 HTTP/1.1
GET: /credits/234234/23-01-2012 HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/xml
<creditBalance>
    <amount>10</amount>
</creditBalance>
GET: /credits/234234/23-01-2012 HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/xml
<creditBalance>
    <amount>10</amount>
</creditBalance>

POST: /credits/234234/23-01-2012 HTTP/1.1
<decrement>
    <amount>2</amount>
</decrement>
GET: /credits/234234/23-01-2012 HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/xml
<creditBalance>
    <amount>10</amount>
</creditBalance>

POST: /credits/234234/23-01-2012 HTTP/1.1
<decrement>
    <amount>2</amount>
</decrement>

HTTP/1.1 200 OK
what would we do next?
Inlining...
<list of=”user”>
  <link rel="user" href="..." />
  <link rel="user" href="..." />
  <link rel="user" href="..." />
</site>
Inlining...
<list of=”user”>
  <user href="..." />
  <user href="..." />
  <user href="..." />
</site>
Inlining...
<list of=”user”>
  <user href="...">
     <userName>jimb@thoughtworks.com</userName>
     <status>Active</status>
  </user>
  <user href="..." />
  <user href="..." />
</site>
THANKS!
{
    “is” : [“link” “list”],
    rest-discuss: “http://tech.groups.yahoo.com/group/rest-discuss/”,
    httpbis: “http://tools.ietf.org/wg/httpbis/”,
    object-net: “http://the-object.net”,


}

Rest experience-report

Editor's Notes

  • #2 Intro to me\n\nGive brief context of api \nEntitlements\nMultiple sites\nUsers\nLicences\nCredits\n\nExisting SOAP API\n
  • #3 Intro to me\n\nGive brief context of api \nEntitlements\nMultiple sites\nUsers\nLicences\nCredits\n\nExisting SOAP API\n
  • #4 \n
  • #5 \n
  • #6 \n
  • #7 \n
  • #8 \n
  • #9 \n
  • #10 \n
  • #11 \n
  • #12 \n
  • #13 TWO IMPORTANT POINTS....\n
  • #14 \n
  • #15 \n
  • #16 \n
  • #17 \n
  • #18 \n
  • #19 \n
  • #20 \n
  • #21 Down on the upside - Kevlin Henney\n\nhttp://www.artima.com/weblogs/viewpost.jsp?thread=341297\n
  • #22 Down on the upside - Kevlin Henney\n\nhttp://www.artima.com/weblogs/viewpost.jsp?thread=341297\n
  • #23 Down on the upside - Kevlin Henney\n\nhttp://www.artima.com/weblogs/viewpost.jsp?thread=341297\n
  • #24 Down on the upside - Kevlin Henney\n\nhttp://www.artima.com/weblogs/viewpost.jsp?thread=341297\n
  • #25 Down on the upside - Kevlin Henney\n\nhttp://www.artima.com/weblogs/viewpost.jsp?thread=341297\n
  • #26 Down on the upside - Kevlin Henney\n\nhttp://www.artima.com/weblogs/viewpost.jsp?thread=341297\n
  • #27 Down on the upside - Kevlin Henney\n\nhttp://www.artima.com/weblogs/viewpost.jsp?thread=341297\n
  • #28 Down on the upside - Kevlin Henney\n\nhttp://www.artima.com/weblogs/viewpost.jsp?thread=341297\n
  • #29 Down on the upside - Kevlin Henney\n\nhttp://www.artima.com/weblogs/viewpost.jsp?thread=341297\n
  • #30 Down on the upside - Kevlin Henney\n\nhttp://www.artima.com/weblogs/viewpost.jsp?thread=341297\n
  • #31 Down on the upside - Kevlin Henney\n\nhttp://www.artima.com/weblogs/viewpost.jsp?thread=341297\n
  • #32 \n
  • #33 \n
  • #34 \n
  • #35 \n
  • #36 \n
  • #37 \n
  • #38 \n
  • #39 \n
  • #40 \n
  • #41 \n
  • #42 \n
  • #43 \n
  • #44 \n
  • #45 \n
  • #46 \n
  • #47 http://crazytownmayor.com/blog/wp-content/uploads/2010/02/Footprints.png\n
  • #48 \n
  • #49 \n
  • #50 \n
  • #51 \n
  • #52 \n
  • #53 \n
  • #54 \n
  • #55 \n
  • #56 \n
  • #57 \n
  • #58 \n
  • #59 \n
  • #60 \n
  • #61 \n
  • #62 \n
  • #63 \n
  • #64 \n
  • #65 http://www.ba-stores.com/product-logos/originals/20820_WC20StretchingTimeClock.jpg\n\njson and xml\ninlining\nshortcuts\nrepresentation framework\ncaching+etags\n\nCompatibility matrix testing\nPerformance testing\n\n\n
  • #66 \n
  • #67 \n
  • #68 \n
  • #69 https://devcentral.f5.com/weblogs/images/devcentral_f5_com/weblogs/macvittie/WindowsLiveWriter/TheFourEventsoftheDecadethatShapedtheFut_6993/hindsight_2.jpg\n\nJSON from the start (Show demo)\nBuild a client\nA lot of discussions - more of a basis now\nTOO MUCH LINKING ? Focus on resources - perhaps didnt need a link to the &amp;#x201C;entitlements&amp;#x201D; in order to query, could just send to the USER object\n\n
  • #70 \n