REST - You're Doing It Wrong

Preview:

DESCRIPTION

Delivered during NRW Conf on 09.09.2011 in Wuppertal, Germany

Citation preview

ReSTyou’re doing it

wrong!Sergey ShishkinMT AG

http://www.mt-ag.comhttp://shishkin.org@sshishkin

ReSTyou’re doing it

wrong!Sergey ShishkinMT AG

http://www.mt-ag.comhttp://shishkin.org@sshishkin

A Tale of an Ice-Cream Maker

by Sebastien Lambla

Architecture

of the web

Loose Coupling

Simplicity,Uniformity

Scalability,Performance

You MightNot Need It

/products/books/can-haz-rest

/products ? title=can-haz-rest

/Y2FuLWhhei1yZXN0%3D

Which URI is RESTful?

POST /REST.svc

<PlaceOrder> <Product> 1234 </Product> <Price> 19.90 </Price> <Qty> 2 </Qty></PlaceOrder>

POST /REST.svc{ PlaceOrder: { Product: 1234, Price: 19.90, Quantity: 2 }}

Richardson RESTMaturity Model

None

GET /REST.svc ? op=PlaceOrder & product=1234 & qty=2

URI Tunneling

POST /Orders.svc ? product=1234 & qty=2

GET idempotent, safe

POST non idempotent, unsafe

PUT idempotent, unsafe

DELETE idempotent, unsafe

HEAD idempotent, safe

OPTIONS idempotent, safe

GET /Users/1234…PUT /Users/1234{ login: bob, … userpic: {…}, settings: {…}}

Resourcesare notEntities

CRUD

CRUD

GET /Profile/SettingsPOST /Profile/Settings

POST /Profile/Image

URI Templates/products/{id}

Richardson RESTMaturity Model

URI

None

Versioning/api/v2

GET /api

Accept: application/vnd.example+xml; version=2, application/xml

Languages/de/product/1234/product/1234 ?

lang=fr

GET /product/1234

Accept-Language: de

Richardson RESTMaturity Model

HTTP

URI

None

GET /Products/1234…Content-Type: application/json{ title: can-haz-rest, price: 19.99, …}

Generic Media Types

application/atom+xml;type=feed

application/vnd.example+json

GET /Products/1234

{ title: can-haz-rest, price: 19.99,}

And What Now?

{ title: “can-haz-rest”, links: [ { rel: “buy”, link: “Product/1234/buy” } ]}

Richardson RESTMaturity Model

Hypermedia

HTTP

URI

None

It’s all about resources,

Representations,

And Hypermedia!

It’s All About Resources,

Representations, And

Hypermedia!

Beratung Projekte Schulungen

Application Lifecycle Design Entwicklung

Architektur SOA Cloud Computing

BalckeBalcke-Dürr-Allee 9, 40882 Ratingen www.mt-ag.com info@mt-ag.com

Sergey Shishkinhttp://shishkin.orgsergei.shishkin@gmail.com@sshishkin

Links & Credits• Richardson Maturity Model

– http://martinfowler.com/articles/richardsonMaturityModel.html• The Tale of the Ice-Cream Maker

– http://serialseb.blogspot.com/2009/06/fighting-for-rest-or-tale-of-ice-cream.html• REST in Practice

– http://restinpractice.com/• REST Content on InfoQ

– http://www.infoq.com/rest/

Images:– Web: http://www.flickr.com/photos/zzathras777/1546040168/– Mirrors: http://www.flickr.com/photos/coolmikeol/4156970741/– Rope: http://www.flickr.com/photos/visualpanic/2759322646/– Soup: http://www.flickr.com/photos/wallyg/562283586/– Ice-cream van: http://www.flickr.com/photos/estherase/516542355/– Ice-cream: http://www.flickr.com/photos/pinksherbet/3398923323/