The hypermedia api

  • 2,892 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
2,892
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
8
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. THE HYPERMEDIA API Ben Longden / @blongden
  • 2. WHO ARE YOU? SOFTWARE ENGINEER & MANAGERInviqa, Session Digital, Sensio Labs UK
  • 3. Twitter: blongdenGitHub: blongdenEmail: ben@nocarrier.co.uk
  • 4. ARCHITECTURAL STYLES
  • 5. RPC http://.../create_account.php? email_addr=user@example.com&passwd_hash=2ab548fae3162ccfa1a2d41a55557a92& user_name=CrunchAll
  • 6. RICHARDSON MATURITY LEVEL 0
  • 7. THE SWAMP OF POX PLAIN OLD XML (OR JSON)
  • 8. <user> <emailaddr>user@example.com</emailaddr> <username>CrunchAll</username></user>
  • 9. WS-*SOAP
  • 10. RICHARDSON MATURITY LEVEL 1
  • 11. IDENTIFICATION OF RESOURCES PRETTY URLS
  • 12. NO VERBSFIND THE NOUNS
  • 13. Users can create messages that are visible to other users who follow them.
  • 14. CRAFT URLS FOR YOUR RESOURCES http://.../users/{name} http://.../messages/{id}
  • 15. SUBSETS OF DATA http://.../users/blongden/messages
  • 16. HTTP AS A TUNNEL
  • 17. METHODSMETADATAPAYLOAD
  • 18. HTTP IS SUCCESSFULAUTHENTICATION, CACHE, CONTENT NEGOTIATION
  • 19. RICHARDSON MATURITY LEVEL 2 USE THE VERBS THAT HTTP PROVIDES GET POST PUT DELETE OPTIONS TRACE HEAD CONNECT PATCH
  • 20. SAFE ACTIONS HEAD & GET
  • 21. IDEMPOTENT ACTIONS HEAD, GET, PUT, DELETE OPTIONS, TRACE
  • 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. GET /users/blongden/messages HTTP/1.1Host: example.com
  • 24. POST /users/blongden/messages HTTP/1.1Host: example.com
  • 25. PUT /users/blongden/messages/1 HTTP/1.1Host: example.com
  • 26. DELETE /users/blongden/messages/1 HTTP/1.1Host: example.com
  • 27. RICHARDSON MATURITY MODEL LEVEL 3 HYPERMEDIA
  • 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. HYPERMEDIAAFFORDANCES
  • 30. [LE] EMBEDDED LINKS<img src=http://example.com/logo />
  • 31. [LO] OUTBOUND LINKS<a href=http://example.com/search title=view search page> Search</a>
  • 32. [LT] TEMPLATED QUERIES <form method=get>...</form>
  • 33. [LN] NON-IDEMPOTENT UPDATES<form method=post>...</form>
  • 34. [LI] IDEMPOTENT UPDATESSUPPORT FOR PUT AND DELETE
  • 35. REGISTERED MEDIA TYPES
  • 36. HALHYPERTEXT APPLICATION LANGUAGE
  • 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. <?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. <?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. LINK RELATIONS
  • 41. SHORT SYNTAX"STYLESHEET", "PROFILE"
  • 42. MICROFORMATS registered link relations
  • 43. IANAregistered link relations
  • 44. CUSTOM LINK RELATIONS http://.../rels/message
  • 45. DESIGNING AHYPERMEDIA TYPE
  • 46. XML OR JSON? HTML? YAML?
  • 47. JSONUBIQUITOUS AND EASY TO PARSE RIGID STRUCTURE
  • 48. XMLUBIQUITOUS BUT HARDER TO PARSE EVOLVABLE
  • 49. { "name": "Ben", "phone": "07777000000"}
  • 50. { "name": "Ben", "phone": [ "07777000000", "07777000001" ]}
  • 51. <?xml version="1.0"?><contact> <name>Ben</name> <phone>07777000000</phone></contact>
  • 52. <?xml version="1.0"?><contact> <name>Ben</name> <phone>07777000000</phone> <phone>07777000001</phone></contact>
  • 53. CONSIDER H-FACTORSDO YOU NEED TO EXTEND AN EXISTING FORMAT?
  • 54. WHY USE A REGISTERED TYPE?
  • 55. EXISTING TOOLS
  • 56. INTEROPERABILITY
  • 57. THE CHATTY API PROBLEM
  • 58. ZOOMTHE HYPERTEXT CACHE PATTERN
  • 59. http://.../users/blongden?zoom=messages{ "_links": { "self": { href: "http://.../users/blongden" }, "messages": { href: "http://.../users/blongden/messages" } } "_embedded": { "messages": { ... } }}
  • 60. COMMON INTERFACE
  • 61. THANK YOU. http://joind.in/8048