rest, http, and the patch verb (with kittens)

13
HTTP, REST and the PATCH verb (accompanied by kittens) Thomas Parslow @almostobsolete http://almostobsolete.net

Upload: almostobsolete

Post on 02-Jul-2015

3.793 views

Category:

Technology


1 download

DESCRIPTION

RESTful web services and the new HTTP PATCH Verb. Plus kittens. My Bar Camp London 9 talk

TRANSCRIPT

Page 1: REST, HTTP, and the PATCH verb (with kittens)

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)

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)

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)

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)

Current main HTTP verbs

GET PUT DELETE POST

Show! Replace! Destroy! Do stuff!

Page 6: REST, HTTP, and the PATCH verb (with kittens)

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)

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)

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)

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)

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)

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)

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)

Thanks for listening!

Questions?

@almostobsolete