64
THE HYPERMEDIA API / Ben Longden @blongden

The hypermedia api

  • Upload
    inviqa

  • View
    2.996

  • Download
    2

Embed Size (px)

Citation preview

Page 1: The hypermedia api

THE HYPERMEDIA API / Ben Longden @blongden

Page 2: The hypermedia api

WHO ARE YOU?SOFTWARE ENGINEER & MANAGER

Inviqa, Session Digital, Sensio Labs UK

Page 3: The hypermedia api
Page 4: The hypermedia api

Twitter: blongden

GitHub: blongden

Email: [email protected]

Page 5: The hypermedia api

ARCHITECTURAL STYLES

Page 6: The hypermedia api

RPChttp://.../create_account.php?

[email protected]&

passwd_hash=2ab548fae3162ccfa1a2d41a55557a92&

user_name=CrunchAll

Page 7: The hypermedia api

RICHARDSON MATURITYLEVEL 0

Page 8: The hypermedia api

THE SWAMP OF POXPLAIN OLD XML

(OR JSON)

Page 9: The hypermedia api

<user> <emailaddr>[email protected]</emailaddr> <username>CrunchAll</username></user>

Page 10: The hypermedia api

WS-*SOAP

Page 11: The hypermedia api

RICHARDSON MATURITYLEVEL 1

Page 12: The hypermedia api

IDENTIFICATION OFRESOURCES

PRETTY URLS

Page 13: The hypermedia api

NO VERBSFIND THE NOUNS

Page 14: The hypermedia api

Users can create messages that are visible to other users who

follow them.

Page 15: The hypermedia api

CRAFT URLS FOR YOURRESOURCES

http://.../users/{name}

http://.../messages/{id}

Page 16: The hypermedia api

SUBSETS OF DATAhttp://.../users/blongden/messages

Page 17: The hypermedia api

HTTP AS A TUNNEL

Page 18: The hypermedia api

METHODSMETADATAPAYLOAD

Page 19: The hypermedia api

HTTP IS SUCCESSFULAUTHENTICATION, CACHE, CONTENT

NEGOTIATION

Page 20: The hypermedia api

RICHARDSON MATURITYLEVEL 2

USE THE VERBS THAT HTTP PROVIDESGET POST PUT DELETE

OPTIONS TRACE HEAD CONNECT PATCH

Page 21: The hypermedia api

SAFE ACTIONSHEAD & GET

Page 22: The hypermedia api

IDEMPOTENT ACTIONSHEAD, GET, PUT, DELETE

OPTIONS, TRACE

Page 23: The hypermedia api

IDENTIFY STATESLIST USERS, LIST A SINGLE USER

LIST MESSAGES, LIST A SINGLE MESSAGECREATE/UPDATE/DELETE A USER

FOLLOW/UNFOLLOW A USER

Page 24: The hypermedia api

GET /users/blongden/messages HTTP/1.1Host: example.com

Page 25: The hypermedia api

POST /users/blongden/messages HTTP/1.1Host: example.com

Page 26: The hypermedia api

PUT /users/blongden/messages/1 HTTP/1.1Host: example.com

Page 27: The hypermedia api

DELETE /users/blongden/messages/1 HTTP/1.1Host: example.com

Page 28: The hypermedia api

RICHARDSON MATURITYMODEL LEVEL 3

HYPERMEDIA

Page 29: The hypermedia api

HYPERMEDIAHypermedia is used as a logical extension of the term

hypertext in which graphics, audio, video, plain text and

hyperlinks intertwine to create a generally non-linear

medium of information.

Page 30: The hypermedia api

HYPERMEDIAAFFORDANCES

Page 31: The hypermedia api

[LE] EMBEDDED LINKS<img src='http://example.com/logo' />

Page 32: The hypermedia api

[LO] OUTBOUND LINKS<a href='http://example.com/search' title='view search page'> Search</a>

Page 33: The hypermedia api

[LT] TEMPLATED QUERIES<form method='get'>...</form>

Page 34: The hypermedia api

[LN] NON-IDEMPOTENTUPDATES

<form method='post'>...</form>

Page 35: The hypermedia api

[LI] IDEMPOTENTUPDATES

SUPPORT FOR PUT AND DELETE

Page 36: The hypermedia api

REGISTERED MEDIA TYPES

Page 37: The hypermedia api

HALHYPERTEXT APPLICATION LANGUAGE

Page 38: The hypermedia api

"_links": { "next": { "href": "/orders?page=2" }, "self": { "href": "/orders" }},"_embedded": { "order": [ "_links": { "customer": { "href": "/customer/bob", "title": "Bob Jones <[email protected]>" }, "self": { "href": "/orders/123" } }, "currency": "USD", "total": 30]}

Page 39: The hypermedia api

<?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 <[email protected]>"/> <total>30</total> <currency>USD</currency> </resource></resource>

Page 40: The hypermedia api

<?php$hal = new \Nocarrier\Hal('/orders');$hal->addLink('next', '/orders?page=2');$hal->addLink('search', '/orders?id={order_id}');

$resource = new \Nocarrier\Hal( '/orders/123', array( 'total' => 30.00, 'currency' => 'GBP', ));

$resource->addLink('customer', '/customer/bob', 'Bob Jones <[email protected]>');$hal->addResource('order', $resource);echo $hal->asXml();echo $hal->asJson();

Page 41: The hypermedia api

LINK RELATIONS

Page 42: The hypermedia api

SHORT SYNTAX"STYLESHEET", "PROFILE"

Page 43: The hypermedia api

MICROFORMATSregistered link relations

Page 45: The hypermedia api

CUSTOM LINK RELATIONShttp://.../rels/message

Page 46: The hypermedia api

DESIGNING AHYPERMEDIA TYPE

Page 47: The hypermedia api

XML OR JSON?HTML? YAML?

Page 48: The hypermedia api

JSONUBIQUITOUS AND EASY TO PARSE

RIGID STRUCTURE

Page 49: The hypermedia api

XMLUBIQUITOUS BUT HARDER TO PARSE

EVOLVABLE

Page 50: The hypermedia api

{ "name": "Ben", "phone": "07777000000"}

Page 51: The hypermedia api

{ "name": "Ben", "phone": [ "07777000000", "07777000001" ]}

Page 52: The hypermedia api

<?xml version="1.0"?><contact> <name>Ben</name> <phone>07777000000</phone></contact>

Page 53: The hypermedia api

<?xml version="1.0"?><contact> <name>Ben</name> <phone>07777000000</phone> <phone>07777000001</phone></contact>

Page 54: The hypermedia api

CONSIDER H-FACTORSDO YOU NEED TO EXTEND AN EXISTING

FORMAT?

Page 55: The hypermedia api

WHY USE A REGISTEREDTYPE?

Page 57: The hypermedia api

INTEROPERABILITY

Page 58: The hypermedia api

THE 'CHATTY API'PROBLEM

Page 59: The hypermedia api

ZOOMTHE HYPERTEXT CACHE PATTERN

Page 60: The hypermedia api

http://.../users/blongden?zoom=messages

{ "_links": { "self": { href: "http://.../users/blongden" }, "messages": { href: "http://.../users/blongden/messages" } } "_embedded": { "messages": { ... } }}

Page 61: The hypermedia api

COMMON INTERFACE

Page 62: The hypermedia api

THANK YOU.http://joind.in/8048

Page 63: The hypermedia api
Page 64: The hypermedia api