REST, HTTP, and the PATCH verb (with kittens)
-
Upload
almostobsolete -
Category
Technology
-
view
3.793 -
download
1
description
Transcript of REST, HTTP, and the PATCH verb (with kittens)
![Page 1: REST, HTTP, and the PATCH verb (with kittens)](https://reader033.fdocuments.us/reader033/viewer/2022052908/55945cfa1a28ab270c8b4715/html5/thumbnails/1.jpg)
HTTP,
REST
and the PATCH verb
(accompanied by kittens)
Thomas Parslow@almostobsolete
http://almostobsolete.net
![Page 2: REST, HTTP, and the PATCH verb (with kittens)](https://reader033.fdocuments.us/reader033/viewer/2022052908/55945cfa1a28ab270c8b4715/html5/thumbnails/2.jpg)
Web services
The web is used by machines as well as humans
Web services are like web sites for machines
Various ways to design web services
RPC
SOAP (please no)
![Page 3: REST, HTTP, and the PATCH verb (with kittens)](https://reader033.fdocuments.us/reader033/viewer/2022052908/55945cfa1a28ab270c8b4715/html5/thumbnails/3.jpg)
HTTP is awesome!
Simple
Common set of operations
Libraries in every language
Compression?
Encryption?
Cacheing?
Http has got it covered...
![Page 4: REST, HTTP, and the PATCH verb (with kittens)](https://reader033.fdocuments.us/reader033/viewer/2022052908/55945cfa1a28ab270c8b4715/html5/thumbnails/4.jpg)
REST
Think in nouns not verbs!
Resources are nouns
Resources are addressable and linked
http://example.com/blogpost/1
NOT: http://example.com/get_blogpost
![Page 5: REST, HTTP, and the PATCH verb (with kittens)](https://reader033.fdocuments.us/reader033/viewer/2022052908/55945cfa1a28ab270c8b4715/html5/thumbnails/5.jpg)
Current main HTTP verbs
GET PUT DELETE POST
Show! Replace! Destroy! Do stuff!
![Page 6: REST, HTTP, and the PATCH verb (with kittens)](https://reader033.fdocuments.us/reader033/viewer/2022052908/55945cfa1a28ab270c8b4715/html5/thumbnails/6.jpg)
Why REST?
Trendy buzzword
Discoverable, self describing APIs
Less special cases and one offs
More maintanable
Less code!
![Page 7: REST, HTTP, and the PATCH verb (with kittens)](https://reader033.fdocuments.us/reader033/viewer/2022052908/55945cfa1a28ab270c8b4715/html5/thumbnails/7.jpg)
Real world example: Telephone conference control
Conference
Caller
Get conference details (GET)Lock/UnlockRecord On/ Record OffEnd conferenceAdd caller (dialout)Get List Of Callers
Evict callerMute CallerUnmute caller
![Page 8: REST, HTTP, and the PATCH verb (with kittens)](https://reader033.fdocuments.us/reader033/viewer/2022052908/55945cfa1a28ab270c8b4715/html5/thumbnails/8.jpg)
Conference{ "type": "conference", "href": "http://example.com/conferences/1", "head": { "allow": [ "GET", "DELETE", "PUT", "PATCH" ], "created_at": "2011-10-21T10:56:54Z", "related": { "callers": {"href": "http://example.com/conferences/1/callers"} }, "body": { "recording": false, "locked": false }}
Caller List{ "type": "caller-list", "href": "http://example.com/api/v1/conferences/1/callers", "head": { "allow": ["GET", "POST"] }, "body": [ {"href": "http://example.com/conferences/1/callers/1"} ]}
Caller{ "type": "caller", "href": "http://example.com/conferences/1/callers/1", "head": { "allow": [ "GET", "DELETE", "PUT", "PATCH" ] }, "body": { "phone_number": "07951261227", "name": "Tom", "type": "chair", "muted": false }}
Real world example: Telephone conference control Conference
Caller
![Page 9: REST, HTTP, and the PATCH verb (with kittens)](https://reader033.fdocuments.us/reader033/viewer/2022052908/55945cfa1a28ab270c8b4715/html5/thumbnails/9.jpg)
Real world example: Telephone conference control
Conference
Caller
Get conference details (GET)Lock/Unlock (PUT)Record On/ Record Off (PUT)End conference (DELETE)
Get caller details (GET)Evict caller (DELETE)Mute Caller (PUT)Unmute caller (PUT)
Caller ListGet list of callers (GET)Add caller (dialout) (POST)
![Page 10: REST, HTTP, and the PATCH verb (with kittens)](https://reader033.fdocuments.us/reader033/viewer/2022052908/55945cfa1a28ab270c8b4715/html5/thumbnails/10.jpg)
Partial updates
WHY?
Efficiency: Large resources
Concurrency: Multiple people changing at once
Approaches used:
Overloaded POST - One of operations are bad :(
Split up resource - End up with unnatural resource divisions
![Page 11: REST, HTTP, and the PATCH verb (with kittens)](https://reader033.fdocuments.us/reader033/viewer/2022052908/55945cfa1a28ab270c8b4715/html5/thumbnails/11.jpg)
The PATCH Verb
New HTTP verb
Partially updates a document
Neither idempotent nor safe
Patch format unspecified
http://tools.ietf.org/html/rfc5789
![Page 12: REST, HTTP, and the PATCH verb (with kittens)](https://reader033.fdocuments.us/reader033/viewer/2022052908/55945cfa1a28ab270c8b4715/html5/thumbnails/12.jpg)
JSONPatch
A patch format for JSON documents
http://tools.ietf.org/html/draft-pbryan-json-patch-0
[ { "remove": "/a/b/c" },
{ "add": "/a/b/c", "value": "foo" }, { "replace": "/a/b/c", "value": "bar" }
]
My new Javascript JSONPatch implementation!
https://github.com/dharmafly/jsonpatch.js
![Page 13: REST, HTTP, and the PATCH verb (with kittens)](https://reader033.fdocuments.us/reader033/viewer/2022052908/55945cfa1a28ab270c8b4715/html5/thumbnails/13.jpg)
Thanks for listening!
Questions?
@almostobsolete