Good Form
Building HyperMedia APIs with HTML
David Thomas Hume
@dthume
http://github.com/dthume
Slide 2
Slide 2 text
APIs
Slide 3
Slide 3 text
Contract Negotiation 2003
We’ll give you an API
Sure thing, where do we find the WSDL?
Slide 4
Slide 4 text
RPC :-(
Slide 5
Slide 5 text
REST
Slide 6
Slide 6 text
Contract Negotiation 2013
We’ll give you an API
Sweet! Where do we POST the JSON?
Slide 7
Slide 7 text
No content
Slide 8
Slide 8 text
More RPC :-(
Slide 9
Slide 9 text
“If the API is not being driven by hypertext,
then it cannot be RESTful and cannot be a
REST API. Period. Is there some broken
manual somewhere that needs to be fixed?”
- Roy Fielding
Slide 10
Slide 10 text
Hypermedia APIs
Slide 11
Slide 11 text
“Hypermedia Types are MIME media types
that contain native hyper-linking semantics
that induce application flow.”
- Mike Amundsen
Slide 12
Slide 12 text
“The rest of REST”
- Jon Moore
Slide 13
Slide 13 text
Hypermedia provides...
● Relationships
● Direction
● Flexibility
Provides elements with semantics
● Adds meaning to structure
● Like the _type property common in JSON
● Can use existing “standard” types
○ http://schema.org
● Or use custom types if required
Link Relations == Link Semantics
● @rel attribute can be used on:
○
○
● Expresses the relationship type of the link
● Can be used by clients to distinguish links
Baratheon
Greyjoy
Lannister
Targaryen
Stark
Express Choice
Slide 44
Slide 44 text
Required Fields / Arity
Slide 45
Slide 45 text
Query
Extend with relation semantics
Slide 46
Slide 46 text
So we’re armed with
● Structure
● Relationships
● Semantics
Slide 47
Slide 47 text
“A good REST API is like an ugly website”
- Rickard Oberg
Slide 48
Slide 48 text
Show me the Markup
Slide 49
Slide 49 text
Conclusions
Slide 50
Slide 50 text
Working with HTML APIs
● CSS Selectors (jQuery, JSoup, Jerry etc.)
● XML (if you must: DOM/SAX etc.)
Slide 51
Slide 51 text
The Good
● Explore / Debug / Test - Use a browser
○ No firebug needed! (though still useful)
● Decent support for most languages
● Specs for HTML itself
○ Still need to document @rel and @itemtype use
Slide 52
Slide 52 text
The Bad
● Easy to forget target audience (machines)
● Spec weaknesses:
○ No PUT or DELETE support (yet)
○ Use of @data-rel on s not standard
○ Value of s with @itemprop not standard
● Arguably verbose
Slide 53
Slide 53 text
Application-as-API
● Users want their UI on top of your services
● And they want everything your app can do
● Make the app the API
● Works well with ROCA