intro to hypermedia apis
DESCRIPTION
An introduction to Hypermedia APIs from software developer Eric Oestrich.TRANSCRIPT
![Page 1: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/1.jpg)
Introduction to Hypermedia APIs
Eric Oestrich@ericoestrich
oestri.chsmartlogicsolutions.com
![Page 2: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/2.jpg)
What is a Hypermedia API?
![Page 3: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/3.jpg)
RESTREpresentational State Transfer
![Page 4: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/4.jpg)
Relies Heavily on HTTP● Methods and URI● Media Types● Client Server
![Page 5: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/5.jpg)
Relies Heavily on HTTP (Cont)
● Stateless● Caching● Uniform Interface (HATEOAS)
![Page 6: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/6.jpg)
Methods and URIs
![Page 7: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/7.jpg)
Five RoutesGET /ordersPOST /ordersGET /orders/:idPUT /orders/:idDELETE /orders/:id
![Page 8: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/8.jpg)
GET /ordersList of orders
![Page 9: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/9.jpg)
POST /ordersCreate an order
![Page 10: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/10.jpg)
GET /orders/:idView a single order
![Page 11: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/11.jpg)
PUT /orders/:idReplace or create an order
![Page 12: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/12.jpg)
DELETE /orders/:idDelete an order
![Page 13: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/13.jpg)
A bit about HTTP Verbs
![Page 14: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/14.jpg)
GETRetrieve a resource
![Page 15: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/15.jpg)
POSTMost generic
![Page 16: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/16.jpg)
PUTReplace or Create
Not partial
![Page 17: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/17.jpg)
DELETEDelete a resource
![Page 18: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/18.jpg)
PATCHUpdate partiallyMust be a diff
![Page 19: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/19.jpg)
Media Types
![Page 20: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/20.jpg)
Formats● JSON● XML● XHTML
![Page 21: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/21.jpg)
Setting the Media Type● Accept Headers● Rails way - .:format
![Page 22: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/22.jpg)
Representational basedModels != Representations
![Page 23: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/23.jpg)
Uniform Interface
![Page 24: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/24.jpg)
Uniform Interface● Identification of resources● Manipulation of resources via
representations● Self descriptive messages● Hypermedia as the engine of application
state
![Page 25: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/25.jpg)
Identification of resources
![Page 26: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/26.jpg)
Manipulation of resources via representations
![Page 27: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/27.jpg)
Self descriptive messages
Statelessness
![Page 28: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/28.jpg)
Hypermedia as the engine of application state
HATEOAS
![Page 29: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/29.jpg)
Clients should not know how to build routes
![Page 30: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/30.jpg)
Enter HALJSON cannot describe a link
![Page 31: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/31.jpg)
HAL is a media type for defining links in JSON
application/hal+json
![Page 32: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/32.jpg)
The GoalGET /
![Page 33: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/33.jpg)
Great, now I know what a Hypermedia API is.
![Page 34: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/34.jpg)
How do I make one?
![Page 35: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/35.jpg)
Rails + Lots of GemsAlso monkey patching
![Page 36: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/36.jpg)
Gems● ActiveModel::Serializer● RspecApiDocumentation● Raddocs● A few other handy ones
![Page 37: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/37.jpg)
$ rails new hypermedia_api --skip-test-unit
![Page 38: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/38.jpg)
$ vim Gemfilegem 'raddocs'gem 'active_model_serializers'
![Page 39: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/39.jpg)
$ vim Gemfilegroup :test, :development do gem 'rspec-rails' gem 'rspec_api_documentation'end
![Page 40: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/40.jpg)
Get rspec set up
![Page 41: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/41.jpg)
Create our first acceptance test
![Page 42: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/42.jpg)
Generate models, index action, serializers
![Page 43: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/43.jpg)
Show
![Page 44: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/44.jpg)
Create
![Page 45: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/45.jpg)
Update
![Page 46: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/46.jpg)
Delete
![Page 47: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/47.jpg)
Setup HALLet the monkey patching begin
![Page 48: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/48.jpg)
We're missing something...
![Page 49: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/49.jpg)
$ curl http://localhost:3000/""
![Page 50: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/50.jpg)
Root Resource
![Page 51: Intro to Hypermedia APIs](https://reader036.vdocument.in/reader036/viewer/2022062307/554f6d0bb4c905c8088b52fd/html5/thumbnails/51.jpg)
Questions?Eric Oestrich@ericoestrich
oestri.chsmartlogicsolutions.com