Slide 1

Slide 1 text

Hi! My name is Mårten Gustafson

Slide 2

Slide 2 text

I used to work here...

Slide 3

Slide 3 text

...now I work here... (and I brought give-away readers)

Slide 4

Slide 4 text

Representational State Transfer

Slide 5

Slide 5 text

Representational State Transfer

Slide 6

Slide 6 text

REST

Slide 7

Slide 7 text

RESTful

Slide 8

Slide 8 text

HTTP

Slide 9

Slide 9 text

means of INTEGRATING disparate stuff

Slide 10

Slide 10 text

(my DARK and shameful PAST) * 4 years of: ** IBM WebSphere ** ESB ** SOAP/WSDL ** Enterprisey * REST vs SOAP vs HTTP vs JMS vs WMQ vs PUB/SUB vs EDA vs HA vs D/R

Slide 11

Slide 11 text

INTEGRATIONs

Slide 12

Slide 12 text

APIs

Slide 13

Slide 13 text

INTERFACEs

Slide 14

Slide 14 text

UNIFORM * REST defines a uniform interface * As opposed to SOAP, CORBA, etc

Slide 15

Slide 15 text

GET PUT POST DELETE - list all foo - 501 - create a new foo - 501 a/b/c/foo

Slide 16

Slide 16 text

GET PUT POST DELETE - details of {id} - update the {id} - 501 - delete the {id} a/b/c/foo/{id}

Slide 17

Slide 17 text

VERBs

Slide 18

Slide 18 text

(OPTIONS) * not common (yet) * mention: pre-flight

Slide 19

Slide 19 text

GET * retrieve

Slide 20

Slide 20 text

HEAD * retrieve without content (ie metadata)

Slide 21

Slide 21 text

POST * create (without known id) or update (with/without - unsafe)

Slide 22

Slide 22 text

PUT * update or create with known id (idempotent)

Slide 23

Slide 23 text

DELETE * remove

Slide 24

Slide 24 text

(TRACE) * ?

Slide 25

Slide 25 text

(CONNECT) * ?

Slide 26

Slide 26 text

IDEMPOTENT * Without side effects * Fine to call multiple times

Slide 27

Slide 27 text

safe idempotent unsafe OPTIONS X (x) GET X (x) HEAD X (x) POST X PUT X X DELETE X X TRACE X (x) CONNECT

Slide 28

Slide 28 text

DEVELOPing

Slide 29

Slide 29 text

WELL BEHAVED * be well behaved * read up on HTTP/1.1

Slide 30

Slide 30 text

ETag * The most overlooked HTTP header in API design? Allows concurrency control * if-match: “” * if-none-match: “” * 304 not modified * version number

Slide 31

Slide 31 text

VARY * Tell clients/caches which headers that forms the response (ie what’s the cache-combo) * ie: Vary: Accept ( /foo/bar vs /foo/bar : XML vs JSON)

Slide 32

Slide 32 text

CACHE-CONTROL * age * no-cache * no-store

Slide 33

Slide 33 text

EXPIRES * Expire any cached copies after...

Slide 34

Slide 34 text

BENEFITs

Slide 35

Slide 35 text

CLIENTS PROXIES SERVERS LOAD BALANCERS * will all understand and act accordingly * in addition cool modern software does HTTP/REST out-of-the-box (CouchDB, Riak)

Slide 36

Slide 36 text

PLANNING

Slide 37

Slide 37 text

URLs * What will your URL scheme look like * How will it evolve * Identify natural points of extension/evolution

Slide 38

Slide 38 text

DNS * This is part of your URL * Think about partitioning (subdomains) * Think about future transition, separation, isolation * Does Wildcard DNS make sense to you?

Slide 39

Slide 39 text

SECURITY * HTTPS + basic auth (one stop shop) * API auth (client certificates, OAuth) * SSL cookies

Slide 40

Slide 40 text

VERSIONING * This is the hard part

Slide 41

Slide 41 text

http://api.foo/v1/bar application/xml + easy (ie browser compatible)

Slide 42

Slide 42 text

http://api.foo/v1/bar application/xml - URL changes with version - Breaks the URL = resource REST thingy

Slide 43

Slide 43 text

http://api.foo/bar application/vnd.bar-v1+xml - hard (ie NOT browser compatible)

Slide 44

Slide 44 text

http://api.foo/bar application/vnd.bar-v1+xml + version is independent of URL

Slide 45

Slide 45 text

application/vnd.foo-v1+xml application/vnd.foo-v2+xml * Vary: “Accept”

Slide 46

Slide 46 text

REPRESENTATION

Slide 47

Slide 47 text

http://api.foo/bar application/xml + easy (ie browser compatible)

Slide 48

Slide 48 text

http://api.foo/bar.xml + even easier (ie really browser compatible) - more info in URL

Slide 49

Slide 49 text

http://api.foo/bar application/vnd.bar-v1+xml

Slide 50

Slide 50 text

http://api.foo/bar application/vnd.bar-v1+xml + representation is independent of URL

Slide 51

Slide 51 text

USABILITY

Slide 52

Slide 52 text

PROXIES

Slide 53

Slide 53 text

http://api.foo/v1/bar.xml

Slide 54

Slide 54 text

http://api.foo/v1/bar.xml

Slide 55

Slide 55 text

http://api.foo/v1/bar.xml http://api.foo/bar

Slide 56

Slide 56 text

http://api.foo/v1/bar.xml http://api.foo/bar application/vnd.bar-v1+xml

Slide 57

Slide 57 text

http://api.foo/v1/bar.xml http://api.foo/bar application/vnd.bar-v1+xml

Slide 58

Slide 58 text

http://api.foo/v1/bar.xml http://api.foo/bar application/vnd.bar-v1+xml

Slide 59

Slide 59 text

HATEOAS

Slide 60

Slide 60 text

WAT?!

Slide 61

Slide 61 text

LINKs * State transitions

Slide 62

Slide 62 text

MIMEs * Representations

Slide 63

Slide 63 text

LINK + MIME

Slide 64

Slide 64 text

CONTRACTS * What do we promise our clients? * Read these: - http://martinfowler.com/bliki/TolerantReader.html - http://martinfowler.com/articles/consumerDrivenContracts.html

Slide 65

Slide 65 text

SERIALIZED FORM + Easy programming (initially, typed proxies) - Rigid (will not bend, will break)

Slide 66

Slide 66 text

SCHEMAS * Good for automated testing * If you give them away, assume people will generate proxies (and depend on serialized form) * Consider not providing any (or model them loose, xs:any etc - I’m not sure it’s a good idea)

Slide 67

Slide 67 text

GUARANTEES * Fields annotated with “#userid” will have the following form * Attributes named “email” will conform standard X * This document contains one, and only one field annotated “#id”, which is the unique id for Y

Slide 68

Slide 68 text

ROBUSTNESS

Slide 69

Slide 69 text

1234 Mårten Gustafson * XPath

Slide 70

Slide 70 text

1234 Mårten Gustafson /user/name/last * Rigid

Slide 71

Slide 71 text

1234 Mårten Gustafson //last * Adaptive * Might return multiple

Slide 72

Slide 72 text

1234 Mårten Gustafson //last[1] * Adaptive * Only one

Slide 73

Slide 73 text

1234 Mårten Gustafson * Annotated

Slide 74

Slide 74 text

1234 Mårten Gustafson //last[1] * Still works

Slide 75

Slide 75 text

1234 Mårten Gustafson //*[@id='#name.last'][1] * Adaptive

Slide 76

Slide 76 text

1234 Mårten Gustafson //*[@id='#name.last'][1] * Still works

Slide 77

Slide 77 text

Mårten Gustafson //*[@id='#name.last'][1] * Still works

Slide 78

Slide 78 text

Mårten Gustafson //*[@id='#name.last'][1] * Still works

Slide 79

Slide 79 text

INFORMATION MODELLING * This is hard, usually “versioning hard”

Slide 80

Slide 80 text

#name.first * Format * Values * Guarantees

Slide 81

Slide 81 text

URL DNS MIME LINKS PROXY

Slide 82

Slide 82 text

URL DNS MIME LINKS =CONTRACT

Slide 83

Slide 83 text

?

Slide 84

Slide 84 text

@martengustafson [email protected] http://marten.gustafson.pp.se/talks * Representations