+ All Categories
Home > Documents > The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every...

The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every...

Date post: 10-Jul-2020
Category:
Upload: others
View: 3 times
Download: 0 times
Share this document with a friend
68
@dylanbeattie #ndclondon The Rest of
Transcript
Page 1: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

The Rest of

Page 2: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

"When given a name, a

coordinated set of

architectural constraints

becomes an

architectural style"

Page 3: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

"REST is software design on

the scale of decades:

every detail is intended to promote

software longevity and

independent evolution. Many of the constraints are

directly opposed to short-term efficiency."

Page 4: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

• Client-server

• Stateless

• Cacheable

• Layered System

• Code-on-demand

• Uniform interface

• Hypermedia as the engine of application state

ReST: The Constraints

Page 5: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

ReST: The Constraints

• Client-server

• Stateless

• Cacheable

• Layered System

• Code-on-demand

• Uniform interface

• Hypermedia as the engine of application state

This bit is optional.

Page 6: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

GET /profiles HTTP/1.1

200 OK

Content-Type: application/json

[

{

"id": "dbeat1",

"name": "Dylan Beattie",

}

]

Page 7: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

POST /profiles HTTP/1.1

{

"name": "Mark Rendle",

}

201 Created

Location: http://friendc.demo/profiles/2

{

"id": "markr",

"name": "Mark Rendle"

}

Page 8: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

GET /profiles HTTP/1.1

200 OK

[

{ "id": "dylan", "name": "Dylan Beattie" }

{ "id": "markr", "name": "Mark Rendle" },

{ "id": "benhall", "name": "Ben Hall" },

.

.

/* (2 million users omitted for clarity) */

.

{ "id": "serialseb", "name": "Seb Lambla" }

]

Page 9: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

"Your API is using all our bandwidth!"

"Your API is hammering our

database!"

Page 10: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

GET /profiles?page=1 HTTP/1.1

200 OK

[

{ "id": "dbeat1", "name": "Dylan Beattie" }

{ "id": "markr", "name": "Mark Rendle" },

{ "id": "chrisod", "name": "Chris O’Dell" },

.

.

.

.

{ "id": "serialseb", "name": "Seb Lambla" }

]

Page 11: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

GET /profiles?page=2 HTTP/1.1

200 OK

GET /profiles?page=3 HTTP/1.1

200 OK

GET /profiles?page=4 HTTP/1.1

200 OK

GET /profiles?page=5 HTTP/1.1

204 No Content

Page 12: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

ReST: The Constraints

• Client-server

• Stateless

• Cacheable

• Layered System

• Code-on-demand

• Uniform interface

• Hypermedia as the engine of application state

Page 13: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon ww

w.v

inta

geco

mp

uti

ng.

com

Page 14: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

Choose Your Own Adventure:

NDC London 2016

You've been at the NDC after-party for four hours. You've watched the band, you've had a couple of drinks and met some great people. Now the party is starting to wind down – but the hotel bar's open for another half-hour, and Greg Young's trying to get some people along to a poker club he knows in town...

To go back to your room and sleep, go to page 74

To stop by the hotel bar for a nightcap, go to page 23

To go into town and play poker with Greg, go to page 41

Page 15: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

Hypermedia support in JSON

Page 16: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

JSON+Hypermedia Formats

• JSON-LD• Web Standard - http://www.w3.org/TR/json-ld/

• JSONAPI• http://jsonapi.org/

• Collection+JSON• http://amundsen.com/media-types/collection/

• SIREN• https://github.com/kevinswiber/siren

• HAL• http://stateless.co/hal_specification.html

Page 17: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

JSON-LD

{

"@context": "http://json-ld.org/contexts/person.jsonld",

"@id": "http://dbpedia.org/resource/John_Lennon",

"name": "John Lennon",

"born": "1940-10-09",

"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"

}

Page 18: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

Collection+JSON

Page 19: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

{ "collection" :{

"version" : "1.0","href" : "http://example.org/friends/",

"links" : [{"rel" : "feed", "href" : "http://example.org/friends/rss"},{"rel" : "queries", "href" : "http://example.org/friends/?queries"},{"rel" : "template", "href" : "http://example.org/friends/?template"}

],

"items" : [{

"href" : "http://example.org/friends/jdoe","data" : [

{"name" : "full-name", "value" : "J. Doe", "prompt" : "Full Name"},{"name" : "email", "value" : "[email protected]", "prompt" : "Email"}

],"links" : [

{"rel" : "blog", "href" : "http://examples.org/blogs/jdoe", "prompt" : "Blog"},{"rel" : "avatar", "href" : "http://examples.org/images/jdoe", "prompt" :

"Avatar", "render" : "image"}]

}]

} }

Page 20: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

JSONAPI

Page 21: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

JSONAPI

{"links": {

"self": "http://example.com/posts","next": "http://example.com/posts?page[offset]=2","last": "http://example.com/posts?page[offset]=10"

},"data": [{

"type": "posts","id": "1","attributes": { "title": "JSON API paints my bikeshed!" },"relationships": {

"author": {"links": {

"self": "http://example.com/posts/1/relationships/author","related": "http://example.com/posts/1/author"

},"data": { "type": "people", "id": "9" }

},"comments": {

"links": {"self": "http://example.com/posts/1/relationships/comments","related": "http://example.com/posts/1/comments"

},"data": [

{ "type": "comments", "id": "5" },{ "type": "comments", "id": "12" }

]}

},"links": { "self": "http://example.com/posts/1" }

}]

Page 22: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

SIREN

Page 23: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

SIREN

{ "class": [ "order" ], "properties": { "orderNumber": 42 }, "entities": [

{ "class": [ "items", "collection" ], "rel": [ "http://x.io/rels/order-items" ], "href": "http://api.x.io/orders/42/items"

}, {

"class": [ "info", "customer" ], "rel": [ "http://x.io/rels/customer" ], "properties": { "customerId": "pj123", "name": "Peter Joseph" }, "links": [ { "rel": [ "self" ], "href": "http://api.x.io/customers/pj123" } ]

}], "actions": [

{ "name": "add-item", "title": "Add Item", "method": "POST", "href": "http://api.x.io/orders/42/items", "type": "application/x-www-form-urlencoded", "fields": [

{ "name": "orderNumber", "type": "hidden", "value": "42" }, { "name": "productCode", "type": "text" }, { "name": "quantity", "type": "number" }

] }

], "links": [

{ "rel": [ "self" ], "href": "http://api.x.io/orders/42" }, { "rel": [ "previous" ], "href": "http://api.x.io/orders/41" }, { "rel": [ "next" ], "href": "http://api.x.io/orders/43" }

] }

Page 24: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

HAL

Page 25: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

GET /profiles HTTP/1.1

200 OK

Content-Type: application/hal+json

{

"_links" : {

"self" : { "href" : "http://my.api/profiles?page=1" },

"next" : { "href" : "http://my.api/profiles?page=2" },

"last" : { "href" : "http://my.api/profiles?page=214" }

},

"items:" [

{ "id": "dbeat1", "name": "Dylan Beattie" }

{ "id": "markr", "name": "Mark Rendle" },

{ "id": "benhall", "name": "Ben Hall", },..

{ "id": "serialseb", "name": "Seb Lambla" }

]

}

Page 26: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

GET /profiles/1 HTTP/1.1

200 OK

Content-Type: application/json

{"id": 1,"name": "Dylan Beattie","twitter": "@dylanbeattie","friends" : [{ "id": 5, "name": "Mark Rendle", "twitter" : "@markrendle" },{ "id": 6, "name": "Seb Lambla", "twitter" : "@serialseb" },// another 500 friends here...

]

}

Page 27: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

GET /profiles/1 HTTP/1.1

200 OK

Content-Type: application/json

{"id": 1,"name": "Dylan Beattie","twitter": "@dylanbeattie","friends" : [

{ "id": 5, "name": "Mark Rendle", "twitter" : "@markrendle" },{ "id": 6, "name": "Seb Lambla", "twitter" : "@serialseb" },// another 500 friends here... // another 500 friends here...

],

"updates" : [{ "id" : 2792676,

"message": "On my way to ExCeL to speak at NDC", "date" : "2016-01-14T07:45:43.511Z" },

{ "id" : 2978967, "message": "YAY! I got the front seat on the DLR!", "date" : "2016-01-14T08:42:43.511Z" },

{ "id" : 2982341, "message": "HEY EVERYONE! I JUST MET SCOTT HANSELMAN!", "date" : "2016-01-14T13:21:43.511Z" }

]

}

Page 28: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

GET /profiles/1 HTTP/1.1

200 OK

Content-Type: application/json

{"id": 1,"name": "Dylan Beattie","twitter": "@dylanbeattie","friends" : [{ "id": 5, "name": "Mark Rendle", "twitter" : "@markrendle", "updates" : [{ "id" : 2792676, "message": "Installed DNX beta 7 on my fridge", "date": "2015-04-23T18:25:43.511Z"},

]},{ "id": 6, "name": "Ben Hall", "twitter" : "@benhall" "updates" : [{ "id" : 2792676, "message": "On a train to NDC London", "date" : "2015-04-23T18:25:43.511Z" },{ "id" : 2978967, "message": "Preparing my workshop on Docker", "date" : "2015-05-23T18:25:43.511Z" },

]},{ "id": 9, "name": "Seb Lambla", "twitter", "@serialseb""updates" : [{ "id" : 2792676, "message": "Oops. Tequila.", "date" : "2012-04-23T18:25:43.511Z" },{ "id" : 2978967, "message": "DLR hangovers are the worst", "date" : "2012-04-23T18:25:43.511Z" },

]},

],"updates" : [{ "id": 2792676, "message": "On my way to ExCeL to speak at NDC", "date": "2016-01-14T07:45:43.511Z"},{ "id": 2978967, "message": "YAY! I got the front seat on the DLR!", "date": "2016-01-14T08:42:43.511Z"},{ "id": 2982341, "message": "HEY EVERYONE! I JUST MET SCOTT HANSELMAN!", "date":"2016-01-14T13:21:43.511Z"}]

}

Page 29: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

GET /profiles/1 HTTP/1.1

200 OK

Content-Type: application/json

{"id": 1,"name": "Dylan Beattie","twitter": "@dylanbeattie","friends" : [{ "id": 5, "name": "Ian Cooper", "twitter" : "@icooper", "updates" : [{ "id" : 2792676, "message": "NDC is awesome!", "date" : "2012-04-23T18:25:43.511Z" },{ "id" : 2978967, "message": "Heading back to London", "date" : "2012-04-23T18:25:43.511Z" },

],"friends" : [

{ "id": 6, "name": "Toby Henderson", "twitter" : "@holytshirt" "updates" : [{ "id" : 2792676, "message": "NDC is awesome!", "date" : "2012-04-23T18:25:43.511Z" }, { "id" : 2978967, "message": "Heading back to London", "date" : "2012-04-23T18:25:43.511Z" },

]},{ "id": 9, "name": "Liam Westley", "twitter", "@westleyl"

"updates" : [{ "id" : 2792676, "message": "NDC is awesome!", "date" : "2012-04-23T18:25:43.511Z" }, { "id" : 2978967, "message": "Heading back to London", "date" : "2012-04-23T18:25:43.511Z" },

]},

],},{ "id": 6, "name": "Toby Henderson", "twitter" : "@holytshirt" "updates" : [{ "id" : 2792676, "message": "NDC is awesome!", "date" : "2012-04-23T18:25:43.511Z" },{ "id" : 2978967, "message": "Heading back to London", "date" : "2012-04-23T18:25:43.511Z" },

],"friends" : [

{ "id": 6, "name": "Toby Henderson", "twitter" : "@holytshirt" "updates" : [{ "id" : 2792676, "message": "NDC is awesome!", "date" : "2012-04-23T18:25:43.511Z" }, { "id" : 2978967, "message": "Heading back to London", "date" : "2012-04-23T18:25:43.511Z" },

]},{ "id": 9, "name": "Liam Westley", "twitter", "@westleyl"

"updates" : [{ "id" : 2792676, "message": "NDC is awesome!", "date" : "2012-04-23T18:25:43.511Z" }, { "id" : 2978967, "message": "Heading back to London", "date" : "2012-04-23T18:25:43.511Z" },

]},

],},{ "id": 9, "name": "Liam Westley", "twitter", "@westleyl""updates" : [{ "id" : 2792676, "message": "NDC is awesome!", "date" : "2012-04-23T18:25:43.511Z" },{ "id" : 2978967, "message": "Heading back to London", "date" : "2012-04-23T18:25:43.511Z" },

]},

],"updates" : [{ "id" : 2792676, "message": "Having a great time at NDC!", "date" : "2012-04-23T18:25:43.511Z" },{ "id" : 2978967, "message": "Wow – Oslo is still light at 11pm", "date" : "2012-04-23T18:25:43.511Z" },{ "id" : 2982341, "message": "About to give my talk on REST", "date" : "2012-04-23T18:25:43.511Z" }]

}

Page 30: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

"Your API is using all our bandwidth...

AGAIN!" "Your API is hammering the

database. Again."

Page 31: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

Page 32: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

GET /profiles/1 HTTP/1.1

200 OK

Content-Type: application/hal+json

{

"_links": {"self" : "http://my.api/profiles/1","friends" : "http://my.api/profiles/1/friends","photos" : "http://my.api/profiles/1/photos","updates" : "http://my.api/profiles/1/updates"

},"id": 1,"name" : "Dylan Beattie","twitter" : "@dylanbeattie",

}

Page 33: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

GET /profiles/1 HTTP/1.1200 OK

GET /profiles/1/friends HTTP/1.1200 OK

GET /profiles/1/updates HTTP/1.1200 OK

GET /profiles/1/photos HTTP/1.1200 OK

GET /profiles/1/photos/1234 HTTP/1.1200 OK

GET /profiles/1/photos/1234/comments HTTP/1.1200 OK

GET /profiles/1/photos/1345 HTTP/1.1200 OK

GET /profiles/1/photos/1345/comments HTTP/1.1200 OK

GET /profiles/1/photos/1456 HTTP/1.1200 OK

GET /profiles/1/photos/1456/comments HTTP/1.1200 OK

Page 34: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

"I need to make 50 API calls just to

draw a web page!"

"Our HTTP traffic just increased 50x - what have you

done?"

Page 35: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

GET /profiles/1?expand=updates HTTP/1.1

200 OKContent-Type: application/json

{

"_links": {"self" : "http://my.api/profiles/1","friends" : "http://my.api/profiles/1/friends","photos" : "http://my.api/profiles/1/photos","updates" : "http://my.api/profiles/1/updates"

},"id": 1,"name" : "Dylan Beattie","twitter" : "@dylanbeattie"

"_embedded" : {"updates" : [

{ "id" : 2792676, "message": "On the DLR, en route to NDC", "date" : "2016-01-14T16:25:43.511Z" },{ "id" : 2978967, "message": "Coffee. Wi-fi. Happy.", "date" : "2016-01-14T17:55:43.511Z" },{ "id" : 2982341, "message": "Listening to @petemounce DOSing himself", "date" : "2016-01-14T18:25:43.511Z" }]

}}

Page 36: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

GET /profiles/1 HTTP/1.1

200 OKContent-Type: application/json

{

"_links": {"self" : "http://my.api/profiles/1","friends" : "http://my.api/profiles/1/friends","photos" : "http://my.api/profiles/1/photos","updates" : "http://my.api/profiles/1/updates"

},"id": 1,"name" : "Dylan Beattie","twitter" : "@dylanbeattie",

"height" : 180,"weight" : 95,"location" : { "lat": 59.912854, "lon": 10.7536 },"status" : "Talking about REST at Cambridge DDD Night","hometown" : "London, GB""email" : "[email protected]","website" : "www.dylanbeattie.net","birthdate" : "1978-08-22","last_modified": "2015-08-12T19:45:43.511Z"

}

Page 37: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

PUT /profiles/1 HTTP/1.1Content-Type: application/json

{"name" : "Dylan Beattie","twitter" : "@dylanbeattie","height" : 180,"weight" : 95,"location" : { "lat": 59.912854, "lon": 10.7536 },

"status" : "Talking about HTTP PUT","hometown" : "London, GB""email" : "[email protected]","website" : "www.dylanbeattie.net","birthdate" : "1978-08-22",

}

409 Conflict

Page 38: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

"Why do I need to PUT the entire profile just to

update location?"My updates

keep failing with a 409 Conflict!

Help!"

Page 39: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

PUT /profiles/1/status HTTP/1.1"Talking about HTTP PUT"

204 No Content

Page 40: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

The PATCH method requests that

a set of changesdescribed in the request entity

be applied to the resource

identified by the Request-URI.

The set of changes is represented in a format called a "patch document" identified by a media type.

Page 41: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

PATCH /file.txt HTTP/1.1 Host: www.example.com Content-Type: application/example If-Match: "e0023aa4e" Content-Length: 100

[description of changes]

"PATCH Method for HTTP" - http://tools.ietf.org/html/rfc5789

Page 42: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

PATCH /file.txt HTTP/1.1 Host: www.example.com Content-Type: application/example If-Match: "e0023aa4e" Content-Length: 100

[description of changes]

"PATCH Method for HTTP" - http://tools.ietf.org/html/rfc5789

Page 43: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

PATCH /profiles/1 HTTP/1.1

Content-Type: application/x-unix-diff

11c11

< "status": "Talking about REST at NDC London",

---

> "status": "Showing how to use diff and HTTP PATCH",

200 OK

Page 44: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

PATCH /profiles/1 HTTP/1.1

Content-Type: application/json-patch+jsonIf-Match: "abc123"

[

{ "op": "test", "path": "/last-modified", "value": "2015-06-18T15:25:43.511Z"

},

{ "op": "replace", "path": "/status", "value": "Talking about json-patch at NDC London"

},

]

200 OK

Page 45: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

PATCH /profiles/1 HTTP/1.1

Content-Type: image/nickcage+png

202 Accepted

Page 46: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

"We need to expose forenames and

surname separately"

"We're replacing hometown with

an ISO3166 country code"

Page 47: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

GET /profiles/1 HTTP/1.1

200 OKContent-Type: application/hal+json

{

"_links": { ... },"id": 1,"forename" : "Dylan","surname" : "Beattie","twitter" : "@dylanbeattie","height" : 180,"weight" : 102,"location" : { "lat": 59.912854, "lon": 10.7536 },"status" : "Talking about REST at NDC London 2016","hometown" : { "city" : "London", "country": "GB" }"email" : "[email protected]","website" : "www.dylanbeattie.net","birthdate" : "1978-08-22","last_modified": "2015-06-18T15:25:43.511Z"

}

Page 48: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

"Hey! Your API broke our app!"

"Our website just stopped working"

"None of our reports work!"

"YOU BROKE THE INTERNET."

Page 49: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

Oops.

Page 50: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

• The easiest thing to do is

...never break anything!

• ...but : "REST is software design on

the scale of

decades"

Page 51: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

API Versioning Done Wrong

(with thanks to @troyhunt)

Page 52: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

GET /v2/profiles/1

Accept: application/json

200 OK

{ ... }

Page 53: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

GET /profiles/1

Accept: application/vnd.myapi.v2+json

200 OK

{ ... }

Page 54: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

GET /profiles/1

Accept: application/json

X-MyApi-Version: 2

200 OK

{ ... }

Page 55: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

"is version 2 of a profile

the same resourceas version 1?"

"Of course they are! They represent the

same person!"

"Don't be daft. They're completely

different."

Page 56: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

"Of course they are! They represent the same person!"

"Don't be daft. They're completely different."

GET /api/v2/profilesAccept: application/json

GET /api/profilesAccept: application/vnd.myapi.v2+json

"Oh, forget ReST! Let's just use custom headers"

GET /api/profilesX-MyApi-Version: 2

Page 57: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

...and on the server?

Branch the codebase for

separate versions?

One codebase, many versions?

Page 58: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

Branch the codebase for

separate versions?

One codebase, many versions?

[VersionedRoute("api/profiles/{name}", 2)] [Route("api/v2/profiles/{name}")] public Profile GetV2(string name) {

/* write your program here! */

}

Page 59: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

"We hired the CFO's teenage son to build

us a mobile app""We just found

out LinkBait.com is asking for our

users' login details!"

Page 60: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

OAuth 2

Page 61: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

Page 62: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

End User LinkBait.com www.us.com api.us.com

Login Page

[data]Hey! Here's your

web page!

Username + password

Page 63: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

"Hey – this code works on my

machine but it fails in production!"

"Your API keeps crashing every time we send

requests to it."

Page 64: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

http://bit.ly/1Kcat0f

Page 65: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

NGrokhttps://ngrok.com/

Secure tunnels from the web to localhost

Page 66: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

RunScopehttps://www.runscope.com/

Monitoring and debugging for web APIs

Page 67: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

@dylanbeattie #ndclondon

Page 68: The Rest of · @dylanbeattie #ndclondon "REST is software design on the scale of decades: every detail is intended to promote software longevity and independent evolution. Many of

Thank you!

@dylanbeattie

#ndclondon


Recommended