rest in peace @ ipc 2012 in mainz

Post on 08-May-2015

736 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Presentation given at the International PHP Conference 2012 in Mainz, about the REST architectural style.

TRANSCRIPT

Alessandro Nadalin | NAMSHI.com

REST in peace

AGENDA

●Vol. 1: REST in a nutshell○Tenets○Antipatterns

●Vol. 2: To the rescue○HTTP cache○HATEOAS

Sorry for the ugly slide.

There will be others.Really sorry.

REST in a nutshell:

1. Client <> Server

REST in a nutshell:

2. Stateless

3. Cacheable

REST in a nutshell:

REST in a nutshell:

4. Layered system

REST in a nutshell:

5. Uniform interface

And obviously nobody had a clue

ANTIPATTERNS

1URIs

"REST is about

cool URI design"

http://apple.com/users/1/licenses/4.json

"REST is about

cool URI design"

http://apple.com/users/1/licenses/4.json

http://apple.com/site/en_US/showUsers.jsp?uid=1&license=4

is OK too

but

cool URIs help youthink in term of resources

David Zuelke

2URIs (bis)

GET /users POST /users PUT /users/{id} DELETE /users/{id} ...

REST follows a URI schema

GET /users POST /users PUT /users/{id} DELETE /users/{id} ...

REST follows a URI schema

what if you change yourURL?

Yeah, client is broken

RESTful clients shouldbe driven by service'shypermedia controls

Roy Fielding : http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven

HATEOAS

3POST is cool

said SOAP 1.1

said SOAP 1.1

loosing meaningful verbs at the protocol level

loosing meaningful verbs at the protocol level

nothing cacheable by default

loosing meaningful verbs at the protocol level

nothing cacheable by default

what about bookmarking?

4500 is your friend

said SOAP( again )

GET /users/300Host: www.example.com

HTTP/1.1 500 Internal Server ErrorEtag: 1234X-Powered-By: php/5.3...

The record cannot be found

GET /users/300Host: www.example.com

HTTP/1.1 500 Internal Server ErrorEtag: 1234X-Powered-By: php/5.3...

The record cannot be found

GET /users/300Host: www.example.com

The HTTP protocol is awesome,and lets you return meaningful anduniversally-understood status codes

404 Not Found

202 Accepted

202 Accepted

You get an immediate OK, and the operation will hopefully complete

Pause

World Wide Web

the largest data-exchange network on the planet

And meanwhile, at Facebook...

12TB of new data every day

(2 years ago)500 million users

And meanwhile, at Google...

1 billion unique monthly googlers

via HTTP, baby!

HTTP in a nutshell:

1. Client <> Server

HTTP in a nutshell:

2. Stateless

http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html

3. widespread cache spec

HTTP in a nutshell:

HTTP in a nutshell:

4. Layered systemOrigin server

Reverse proxy

Great chinese (fire)wall

Company proxy

Firefox

HTTP in a nutshell:

5. it is the uniform interfacebetween clients and servers

HTTP bleeds REST

1. caching & scalability

Local

Shared/proxy

Shared/reverse proxy

Types of cache

Local

Shared/proxy

Shared/reverse proxy

Types of cache

Local

Shared/proxy

Shared/reverse proxy

Types of cache

Local

Shared/proxy

Shared/reverse proxy

Types of cache

on the server side

Caching withExpiration(example)

HTTP/1.1 200 OKHost: www.example.comExpires: 0

HTTP/1.1 200 OKHost: www.example.comExpires: 0

HTTP/1.1 200 OKHost: www.example.comExpires: Tue, 31 Jan 2013 01:00 GMT

HTTP/1.1 200 OKHost: www.example.comCache-Control: max-age=60, public

HTTP/1.1 200 OKHost: www.example.comCache-Control: max-age=60, public

HTTP/1.1 200 OKHost: www.example.comCache-Control: max-age=60, public

Cacheable for 60 seconds

HTTP/1.1 200 OKHost: www.example.comCache-Control: max-age=60, public

Cacheable by both local and shared caches

but hey, you say

HTTP's cache fails when dealing with really dynamic pages, because consumers will always have to hit the

origin server, although a part of the page would be cacheable ( header and footer, for example )

Nope

Nope

ESI was built for thathttp://www.w3.org/TR/esi-lang

<esi:include src="http://php2start.com/talks/1" />

<esi:include src="http://php2start.com/talks/1" />

<esi:include src="http://php2start.com/talks/1" />

1s (tweets)

3600 post

<esi:include src='tweets.html' />

<esi:include src='article/12.html' />

So what does HTTP cache is meant to solve?

Less work

because the hard work is delegated to the browser/proxy

http://www.flickr.com/photos/snakphotography/5004775320/sizes/o/in/photostream/

evolve

because cache is abstracted from the application

loose coupling

because caching is bound to the protocol, HTTP, not to your implementation ( Sf, RoR, Django )

2. adaptability & durability

Hypermediaanother long-time friend

Linksoutrageously simplifying

<link rel="payment" href="/checkout" type="text/html" ... />

<link rel="payment" href="/checkout" type="text/html" ... />

<link rel="payment" href="/checkout" type="text/html" ... />

<link rel="payment" href="/checkout" type="text/html" ... />

HTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /users/1

POST /usersHost: www.example.com

HTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /users/1

POST /usersHost: www.example.com

HTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /new-users-db/1

POST /usersHost: www.example.com

HTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /new-users-db/1

POST /usersHost: www.example.com

consumers of your API are able to followthe changes of your design

everything seems cool

But why REST?

Pros

Performances

Pros

Scalability

Pros

Durability

amazon.com

Alex Nadalin

Alex Nadalinodino.org

Alex Nadalin

@_odino_

odino.org

Alex Nadalin

@_odino_

odino.org

Alex Nadalin

@_odino_

odino.org

Alex Nadalin

@_odino_

odino.org DXB

Alex Nadalin

@_odino_

odino.org DXB

We're hiring!

In Dubai.

In Dubai.

alex.nadalin@namshi.com

In Dubai.

alex.nadalin@namshi.com

@_odino_

In Dubai.

alex.nadalin@namshi.com

@_odino_

TALK TO ME!

Creditshttp://www.flickr.com/photos/larachris/16564077/sizes/o/in/photostream/

http://www.flickr.com/photos/ashatenbroeke/4367373081/sizes/z/in/photostream/http://www.flickr.com/photos/yourdon/3140270189/sizes/l/in/photostream/http://www.flickr.com/photos/jox1989/4964706072/sizes/l/in/photostream/http://www.flickr.com/photos/brainfg/168506259/sizes/o/in/photostream/

http://www.flickr.com/photos/norte_it/3897091546/sizes/o/in/photostream/http://www.zdnet.com/blog/service-oriented/soap-versus-rest-a-matter-of-style/3568

http://www.flickr.com/photos/turtlemom_nancy/2046347762/sizes/l/in/photostream/http://www.flickr.com/photos/juanpg/3333385784/sizes/z/in/photostream/http://www.flickr.com/photos/congvo/301678287/sizes/l/in/photostream/

http://www.flickr.com/photos/ihasb33r/2573196546/sizes/z/in/photostream/http://www.flickr.com/photos/martin_heigan/4544138976/sizes/o/in/photostream/

http://www.flickr.com/photos/cknara/4195099999/sizes/o/in/photostream/http://www.flickr.com/photos/1080p/3076529265/sizes/l/in/photostream/

http://www.flickr.com/photos/adamrice/280300202/sizes/l/in/photostream/http://www.flickr.com/photos/tomer_a/541411897/sizes/o/in/photostream/http://www.flickr.com/photos/subpra/4514008262/sizes/l/in/photostream/

http://www.flickr.com/photos/lippincott/2539720043/sizes/l/in/photostream/http://www.flickr.com/photos/rawryder/5086090931/sizes/l/in/photostream/http://www.flickr.com/photos/robboudon/5312731161/sizes/l/in/photostream/

http://www.flickr.com/photos/bc-burnslibrary/4158243488/sizes/o/in/photostream/http://www.flickr.com/photos/13606325@N08/2416993706/sizes/o/in/photostream/

http://www.flickr.com/photos/neothezion/5135841069/sizes/l/in/photostream/http://www.flickr.com/photos/planetschwa/2494067809/http://www.flickr.com/photos/thomasthomas/258931782/

http://www.flickr.com/photos/rustyboxcars/2629631562/sizes/l/in/photostream/http://www.flickr.com/photos/ell-r-brown/4138727474/sizes/l/in/photostream/http://www.flickr.com/photos/noah123/5082076630/sizes/z/in/photostream/http://www.flickr.com/photos/jungle_boy/220181177/sizes/l/in/photostream/

http://www.flickr.com/photos/prettydaisies/872539081/sizes/l/in/photostream/http://www.flickr.com/photos/kaptainkobold/76256150/sizes/o/in/photostream/

http://www.flickr.com/photos/uomoincravatta/1438372865/sizes/z/in/photostream/

top related