The hypermedia api

3,343 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
3,343
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

The hypermedia api

  1. 1. THE HYPERMEDIA API Ben Longden / @blongden
  2. 2. WHO ARE YOU? SOFTWARE ENGINEER & MANAGERInviqa, Session Digital, Sensio Labs UK
  3. 3. Twitter: blongdenGitHub: blongdenEmail: ben@nocarrier.co.uk
  4. 4. ARCHITECTURAL STYLES
  5. 5. RPC http://.../create_account.php? email_addr=user@example.com&passwd_hash=2ab548fae3162ccfa1a2d41a55557a92& user_name=CrunchAll
  6. 6. RICHARDSON MATURITY LEVEL 0
  7. 7. THE SWAMP OF POX PLAIN OLD XML (OR JSON)
  8. 8. <user> <emailaddr>user@example.com</emailaddr> <username>CrunchAll</username></user>
  9. 9. WS-*SOAP
  10. 10. RICHARDSON MATURITY LEVEL 1
  11. 11. IDENTIFICATION OF RESOURCES PRETTY URLS
  12. 12. NO VERBSFIND THE NOUNS
  13. 13. Users can create messages that are visible to other users who follow them.
  14. 14. CRAFT URLS FOR YOUR RESOURCES http://.../users/{name} http://.../messages/{id}
  15. 15. SUBSETS OF DATA http://.../users/blongden/messages
  16. 16. HTTP AS A TUNNEL
  17. 17. METHODSMETADATAPAYLOAD
  18. 18. HTTP IS SUCCESSFULAUTHENTICATION, CACHE, CONTENT NEGOTIATION
  19. 19. RICHARDSON MATURITY LEVEL 2 USE THE VERBS THAT HTTP PROVIDES GET POST PUT DELETE OPTIONS TRACE HEAD CONNECT PATCH
  20. 20. SAFE ACTIONS HEAD & GET
  21. 21. IDEMPOTENT ACTIONS HEAD, GET, PUT, DELETE OPTIONS, TRACE
  22. 22. IDENTIFY STATES LIST USERS, LIST A SINGLE USER LIST MESSAGES, LIST A SINGLE MESSAGE CREATE/UPDATE/DELETE A USER FOLLOW/UNFOLLOW A USER
  23. 23. GET /users/blongden/messages HTTP/1.1Host: example.com
  24. 24. POST /users/blongden/messages HTTP/1.1Host: example.com
  25. 25. PUT /users/blongden/messages/1 HTTP/1.1Host: example.com
  26. 26. DELETE /users/blongden/messages/1 HTTP/1.1Host: example.com
  27. 27. RICHARDSON MATURITY MODEL LEVEL 3 HYPERMEDIA
  28. 28. HYPERMEDIA Hypermedia is used as a logical extension of the termhypertext in which graphics, audio, video, plain text and hyperlinks intertwine to create a generally non-linear medium of information.
  29. 29. HYPERMEDIAAFFORDANCES
  30. 30. [LE] EMBEDDED LINKS<img src=http://example.com/logo />
  31. 31. [LO] OUTBOUND LINKS<a href=http://example.com/search title=view search page> Search</a>
  32. 32. [LT] TEMPLATED QUERIES <form method=get>...</form>
  33. 33. [LN] NON-IDEMPOTENT UPDATES<form method=post>...</form>
  34. 34. [LI] IDEMPOTENT UPDATESSUPPORT FOR PUT AND DELETE
  35. 35. REGISTERED MEDIA TYPES
  36. 36. HALHYPERTEXT APPLICATION LANGUAGE
  37. 37. "_links": { "next": { "href": "/orders?page=2" }, "self": { "href": "/orders" }},"_embedded": { "order": [ "_links": { "customer": { "href": "/customer/bob", "title": "Bob Jones <bob@jones.com>" }, "self": { "href": "/orders/123" } }, "currency": "USD", "total": 30]}
  38. 38. <?xml version="1.0"?><resource href="/orders"> <link rel="next" href="/orders?page=2"/> <link rel="search" href="/orders?id={order_id}"/> <resource rel="order" href="/orders/123"> <link rel="customer" href="/customer/bob" title="Bob Jones <bob@jones.com>"/> <total>30</total> <currency>USD</currency> </resource></resource>
  39. 39. <?php$hal = new NocarrierHal(/orders);$hal->addLink(next, /orders?page=2);$hal->addLink(search, /orders?id={order_id});$resource = new NocarrierHal( /orders/123, array( total => 30.00, currency => GBP, ));$resource->addLink(customer, /customer/bob, Bob Jones <bob@jones.com>);$hal->addResource(order, $resource);echo $hal->asXml();echo $hal->asJson();
  40. 40. LINK RELATIONS
  41. 41. SHORT SYNTAX"STYLESHEET", "PROFILE"
  42. 42. MICROFORMATS registered link relations
  43. 43. IANAregistered link relations
  44. 44. CUSTOM LINK RELATIONS http://.../rels/message
  45. 45. DESIGNING AHYPERMEDIA TYPE
  46. 46. XML OR JSON? HTML? YAML?
  47. 47. JSONUBIQUITOUS AND EASY TO PARSE RIGID STRUCTURE
  48. 48. XMLUBIQUITOUS BUT HARDER TO PARSE EVOLVABLE
  49. 49. { "name": "Ben", "phone": "07777000000"}
  50. 50. { "name": "Ben", "phone": [ "07777000000", "07777000001" ]}
  51. 51. <?xml version="1.0"?><contact> <name>Ben</name> <phone>07777000000</phone></contact>
  52. 52. <?xml version="1.0"?><contact> <name>Ben</name> <phone>07777000000</phone> <phone>07777000001</phone></contact>
  53. 53. CONSIDER H-FACTORSDO YOU NEED TO EXTEND AN EXISTING FORMAT?
  54. 54. WHY USE A REGISTERED TYPE?
  55. 55. EXISTING TOOLS
  56. 56. INTEROPERABILITY
  57. 57. THE CHATTY API PROBLEM
  58. 58. ZOOMTHE HYPERTEXT CACHE PATTERN
  59. 59. http://.../users/blongden?zoom=messages{ "_links": { "self": { href: "http://.../users/blongden" }, "messages": { href: "http://.../users/blongden/messages" } } "_embedded": { "messages": { ... } }}
  60. 60. COMMON INTERFACE
  61. 61. THANK YOU. http://joind.in/8048

×