restful web services
DESCRIPTION
An updated version of my RESTful Web Services talk.TRANSCRIPT
RESTful Web Services
Presented by Greg Hines
What Are Web Services?
“The Machine-Readable Web”
Two Styles of Web Service
Service-Oriented ArchitectureSOAP, XML-RPC, etc.
Resource-Oriented Architecture
REST
“The Human-Readable Web”
URLs
HTTP
HTML
URLs + HTTP + HTML
URI + HTTP + HTML
URI + HTTP + Links
URI + HTTP + Hypermedia
Fundamental Web Technologies
REST means using fundamental web technologies idiomatically as the basis for
designing web services.
Why use REST?
The Web Was Designed For It
The Web Was Designed For It(Sort of.)
Appeal to AuthorityAn appeal to authority or argument by authority is a type of argument in logic consisting on basing the truth value of an assertion on the authority, knowledge, expertise, or position of the person asserting it.
–Wikipedia
Roy T. Fielding, Ph.D.
• Co-founder, chairman of the Apache Software Foundation
• Co-founder of the Apache HTTP Project• On IETF working groups for HTTP, URI, and HTML• Architectural principal on HTTP working group • First name on HTTP spec
• Originator of REST
Sam Ruby
• Board member of the Apache Software Foundation• Co-chair of W3C’s HTML Working Group• Co-creator of the Web Feed Validator• Originator of Atom• Secretary of the IETF’s AtomPub working group• Co-author of “RESTful Web Services”
Greg Hines
• Currently giving a presentation about REST
Fielding developed REST while writing HTTP 1.1…
Fielding developed REST while writing HTTP 1.1…
What have you done lately?
Aspects of a RESTfulWeb Service
Resources
Resources
A resource can be practically anything.
• A blog post• A collection of blog posts• An image• A user• Map coordinates• A bank transaction• Search results
Representations
A Kitten
Some Text
Name: BobBreed: TabbyFur Length: MediumFur Color: Gray, Brown, WhiteAge: 8 monthsPersonality: Outgoing, but loves to cuddle.
A Picture
A Drawing
A Haiku
My cat is named Bob.I named him after Bob. Bob’s breath smells like cat food.
A Blog Post
HTML<!DOCTYPE html><html lang="en"> <head> <title>Greg's Blog: My First Blog Post</title> </head> <body> <article> <header> <h1>My First Blog Post</h1> <p>By Greg Hines</p> </header> <p>This is my first blog post. Woo.</p> <footer> <p>Posted on February 2, 2012 at 12:18 PM</p> <ul class="tags"> <li><a href="/tags/awesome">awesome</a></li> </ul> <p><a href="/entries/2012/02/my-first-blog-post">permalink</a></p> </footer> </article> </body></html>
JSON
{ "uri": "/entries/2012/02/my-first-blog-post", "title": "My First Blog Post", "author": "/users/greg", "created": 1328728680, "content": "This is my first blog post. Woo.", "tags": [ "/tags/awesome" ]}
Addressability
AddressabilityEvery resource has at least one URI;
every URI points to a resource.
http://example.com/entries/2012/02/restful-web-services
http://example.com/tags/awesome
http://example.com/
Interface Uniformity
Interface Uniformity
GET POST
Interface Uniformity
GET POST
PUT DELETE
Interface Uniformity
GET POST PUT
DELETE HEAD OPTIONS
Interface Uniformity
GET POST PUT
DELETE HEAD OPTIONS
TRACE CONNECT
Interface Uniformity
GET POST PUT
DELETE HEAD OPTIONS
Interface Uniformity
GET POST PUT
DELETE HEAD OPTIONS
PATCH
Idempotency
Being able to perform an operationmultiple times without changing the result
after the initial operation.
Interface Uniformity
GET POST PUT
DELETE HEAD OPTIONS
Status Codes
Connectedness
Resources Link to Each Other
Connectedness
<?xml version="1.0" encoding="UTF-8"?><resource xmlns="http://example.com/ns/resource"> <content>...</content> <nextResource href="http://example.com/resource/3"/>
<prevResource href="http://example.com/resource/1"/>
</resource>
Connectedness
<?xml version="1.0" encoding="UTF-8"?><resource xmlns="http://example.com/ns/resource"> <content>...</content> <nextResource href="http://example.com/resource/3"/>
<prevResource href="http://example.com/resource/1"/>
</resource>
<link rel="alternate" type="application/atom+xml" href="http://example.com/resource/2.atom" />
HATEOAS
Statelessness
HTTP Is Stateless
Every RequestHappens in Isolation
State Machine
Resource StateServer-Side
Application StateClient-Side
Transferring State
Every HTTP request transfers state between the application and the requested resource.
Resource Applicatione.g. GET
Resource Applicatione.g. PUT
Representation State Transfer
Representation State TransferI see what you did there…
Richardson Maturity Model
Plain Old XMLLevel Zero
ResourcesLevel One
HTTP VerbsLevel Two
HypermediaLevel Three
Strive for Level Three
Be OK with Level Two
Be Embarrassed by Level One
Die in a Fire for Level Zero