34
Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

Embed Size (px)

Citation preview

Page 1: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

Getting Serious with Versioned APIs in Scala

Derrick Isaacson, Director of Development

Page 2: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

Paid

Free

TIE

North

Am

erica

Euro

peAsi

a

Oce

ania

Sout

h Am

erica

Africa

Unkno

wn

0100020003000400050006000700080009000

Hours in editor by region

Page 3: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

Evolvability

Page 4: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development
Page 5: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

Web Site or Web Service

• Servers return XML• IDs -> more HTTP requests• Auth tokens, caching, content type negotiation• Error status codes –> retries• More XML, JPEG, other formats• Series of rendering steps

Page 6: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

“There is no magic dust that makes an HTTP request a web

service request.”

-Leonard Richardson & Sam Ruby, RESTful Web Services

Page 7: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

What is a “web

service”?

Page 8: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

Distributed Computer Architectures

• Distributed memory• RPC services• RESTful services• Distributed file systems• P2P networks• Streaming media

Page 9: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development
Page 10: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development
Page 11: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

Extensibility of REST

Fielding DissertationSection 4.1.2

Page 12: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

REST Components

Data Element Modern Web Examples Versioning

resource the intended conceptual target of a hypertext reference

resource identifier URL, URN

representation HTML document, JPEG image

representation metadata media type, last-modified time

control data if-modified-since, cache-control

Page 13: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

1. Evolving the Resource (not the representation!)1. Uniform identification of resources2. Uniform resource manipulation3. Representation separate from the identity4. Hypermedia as the engine of application state5. Self-descriptive messages

Page 14: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

1. Evolving the Resource

http://lucidchart.com/docs/MyHome/v1 http://lucidchart.com/docs/MyHome/v2

Page 15: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

REST Components

Data Element Modern Web Examples Versioning

resource the intended conceptual target of a hypertext reference

URLs

resource identifier URL, URN

representation HTML document, JPEG image

representation metadata media type, last-modified time

control data if-modified-since, cache-control

Page 16: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

2. Evolving the Resource Identifier

1. Uniform identification of resources2. Uniform resource manipulation3. Representation separate from the identity4. Hypermedia as the engine of application state5. Self-descriptive messages

Page 17: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

2. Evolving URLs & Hypermedia

<diagram>

<images>

<image>

<id>123</id>

</image>

</images>

</diagram>

http://lucidchart.com/imgs/123

http://images.lucidchart.com/imgs/123

Page 18: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

2. Evolving URLs & Hypermedia

<diagram>

<images>

<image>

<id>

http://images.lucidchart.com/imgs/123

</id>

</image>

</images>

</diagram>

Page 19: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

2. Evolving URLs & Uniform Response Codes

http://lucidchart.com/imgs/123 http://images.lucidchart.com/imgs/123

200 OK

<response>

<status>Error</status>

<msg>Not Found</msg>

</response>

404 Not Found

<userMsg>

</userMsg>

301 Moved Permanently

Location: http://images...

fail

Page 20: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

2. Hypermedia with Scala & Play

#routes

GET /users/{id} lucid.getUser(id)

def getUser(id: Int) = {

val accountURI =

routes.App.userAccount(id)

val template = User(accountURI)

Ok(template)

}

Page 21: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

2. Evolving URLs with Scala & Play

# Images moved permanently

GET /imgs/{id} lucid.redirectImages(id)

def redirectImages(id: Int) = {

val location =

“http://images.lucidchart.com/images/”+id

Redirect(location)

}

Page 22: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

REST Components

Data Element Modern Web Examples Versioning

resource the intended conceptual target of a hypertext reference

URLs

resource identifier URL, URN Hypermedia & Uniform Status Codes

representation HTML document, JPEG image

representation metadata media type, last-modified time

control data if-modified-since, cache-control

Page 23: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

3. Self-descriptive Messages

GET /users/123 HTTP 1.1

Host: example.com

User-Agent: XYZ 1.1

Accept: text/html, application/xhtml+xml, application/xml

Keep-Alive: 300

Connection: keep-alive

If-Modified-Since: Fri, 02 Sep 2013 16:47:31 GMT

If-None-Match: "600028c-59fb-474f6852c9dab"

Cache-Control: max-age=60

Date: Fri, 02 Sep 2013 16:47:31 GMT

Via: 1.0, myproxy, 1.1 lucidchart.com (Apache/1.1)

Authorization: Bearer mF_9.B5f-4.1JqM

Page 24: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

3. Self-descriptive Messages

HTTP/1.1 200 OK

Date: Sun, 04 Oct 2013 19:36:25 GMT

Server: Apache/2.2.11 (Debian)

Last-Modified:Fri, 02 Oct 2013 16:48:39 GMT

Etag: "600028c-59fb-474f6852c9dab"

Cache-Control: max-age=300

Accept-Ranges: bytes

Vary: Accept-Encoding

Content-Type: application/xml

Content-Encoding: gzip

Content-Length: 7160

Keep-Alive: timeout=15,max=91

Connection: Keep-Alive

Page 25: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

3. Evolving Resource Metadata & Control Data1. Uniform identification of resources2. Uniform resource manipulation3. Representation separate from the identity4. Hypermedia as the engine of application state5. Self-descriptive messages

Page 26: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

REST Components

Data Element Modern Web Examples Versioning

resource the intended conceptual target of a hypertext reference

URLs

resource identifier URL, URN Hypermedia & Uniform Status Codes

representation HTML document, JPEG image

representation metadata

media type, last-modified time

Self-descriptive w/ Uniform Headers

control data if-modified-since, cache-control

Page 27: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

4. Evolving RepresentationsGET /images/123

200 OK HTTP 1.1

Content-Type: application/xml

<response>

<status>success</status>

<id>123</id>

<image>MTIzNmEyMTM…=</image>

</response>

GET /images/123

Accept: image/jpeg

200 OK HTTP 1.1

Content-Type: image/jpeg

(jpeg image)

Page 28: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

4. Evolving Representations

Standard media types!

http://microformats.org/

http://www.iana.org/assignments/media-types

Page 29: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

GET /users/123

{

name: “John Smith”,

phone: “000-000-0000”,

email: “[email protected]”,

photo: “YWZzYSAyMzR2NQzJ2dzLmZhc20uLC8uLA==“,

groups: [ { id: 234, name: “Team A”, members: […] }, … ],

account: { id: 345, company: “Big Enterprise”, …},

books: [

{ id: 456, name: “RESTful Web Services”, publishDate: … },

{ id: 567, name: “REST in Practice”, … },

],

{

name: “John Smith”,

phone: “000-000-0000”,

email: “[email protected]”,

photo: “https://lucidchart.com/images/abc“,

groups: “https://lucidchart.com/groups?user=123”

account: “https://lucidchart.com/”,

books: “https://books.example.com/catalog?ids=456…”,

}

Page 30: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

4. Custom Media Types

GET /diagrams/v1/123 HTTP/1.1…

GET /diagrams/v1/123… X

Page 31: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

4. Custom Media Types

GET /diagrams/123 HTTP/1.1

Accept: application/vnd.lucid.diagram+xml

GET /diagrams/123 HTTP/1.1

Accept: application/vnd.lucid.diagram-v2+xml…

Page 32: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

REST Components

Data Element Modern Web Examples Versioning

resource the intended conceptual target of a hypertext reference

URLs

resource identifier URL, URN Hypermedia & Uniform Status Codes

representation HTML document, JPEG image Content-type header, uniform media types, and general uniform interface

representation metadata

media type, last-modified time

Self-descriptive w/ Uniform Headers

control data if-modified-since, cache-control

Page 33: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

“The central feature that distinguishes the REST architectural style from other network-based styles is its emphasis on a uniform interface between components. By applying the software engineering principle of generality to the component interface, the overall system architecture is simplified and the visibility of interactions is improved. Implementations are decoupled from the services they provide, which encourages independent evolvability.”

Page 34: Getting Serious with Versioned APIs in Scala Derrick Isaacson, Director of Development

Q & A

http://www.lucidchart.com/jobs