RESTful Web Services

85
RESTful Web Services Presented by Greg Hines

description

An updated version of my RESTful Web Services talk.

Transcript of RESTful Web Services

Page 1: RESTful Web Services

RESTful Web Services

Presented by Greg Hines

Page 2: RESTful Web Services

What Are Web Services?

Page 3: RESTful Web Services

“The Machine-Readable Web”

Page 4: RESTful Web Services

Two Styles of Web Service

Page 5: RESTful Web Services

Service-Oriented ArchitectureSOAP, XML-RPC, etc.

Page 6: RESTful Web Services

Resource-Oriented Architecture

REST

Page 7: RESTful Web Services

“The Human-Readable Web”

Page 8: RESTful Web Services

URLs

Page 9: RESTful Web Services

HTTP

Page 10: RESTful Web Services

HTML

Page 11: RESTful Web Services

URLs + HTTP + HTML

Page 12: RESTful Web Services

URI + HTTP + HTML

Page 13: RESTful Web Services

URI + HTTP + Links

Page 14: RESTful Web Services

URI + HTTP + Hypermedia

Page 15: RESTful Web Services

Fundamental Web Technologies

Page 16: RESTful Web Services

REST means using fundamental web technologies idiomatically as the basis for

designing web services.

Page 17: RESTful Web Services

Why use REST?

Page 18: RESTful Web Services

The Web Was Designed For It

Page 19: RESTful Web Services

The Web Was Designed For It(Sort of.)

Page 20: RESTful Web Services

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

Page 21: RESTful Web Services

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

Page 22: RESTful Web Services

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”

Page 23: RESTful Web Services

Greg Hines

• Currently giving a presentation about REST

Page 24: RESTful Web Services

Fielding developed REST while writing HTTP 1.1…

Page 25: RESTful Web Services

Fielding developed REST while writing HTTP 1.1…

What have you done lately?

Page 26: RESTful Web Services

Aspects of a RESTfulWeb Service

Page 27: RESTful Web Services

Resources

Page 28: RESTful Web Services

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

Page 29: RESTful Web Services

Representations

Page 30: RESTful Web Services

A Kitten

Page 31: RESTful Web Services

Some Text

Name: BobBreed: TabbyFur Length: MediumFur Color: Gray, Brown, WhiteAge: 8 monthsPersonality: Outgoing, but loves to cuddle.

Page 32: RESTful Web Services

A Picture

Page 33: RESTful Web Services

A Drawing

Page 34: RESTful Web Services

A Haiku

My cat is named Bob.I named him after Bob. Bob’s breath smells like cat food.

Page 35: RESTful Web Services

A Blog Post

Page 36: RESTful Web Services

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>

Page 37: RESTful Web Services

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" ]}

Page 38: RESTful Web Services

Addressability

Page 39: RESTful Web Services

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/

Page 40: RESTful Web Services

Interface Uniformity

Page 41: RESTful Web Services

Interface Uniformity

GET POST

Page 42: RESTful Web Services

Interface Uniformity

GET POST

PUT DELETE

Page 43: RESTful Web Services

Interface Uniformity

GET POST PUT

DELETE HEAD OPTIONS

Page 44: RESTful Web Services

Interface Uniformity

GET POST PUT

DELETE HEAD OPTIONS

TRACE CONNECT

Page 45: RESTful Web Services

Interface Uniformity

GET POST PUT

DELETE HEAD OPTIONS

Page 46: RESTful Web Services

Interface Uniformity

GET POST PUT

DELETE HEAD OPTIONS

PATCH

Page 47: RESTful Web Services

Idempotency

Page 48: RESTful Web Services

Being able to perform an operationmultiple times without changing the result

after the initial operation.

Page 49: RESTful Web Services

Interface Uniformity

GET POST PUT

DELETE HEAD OPTIONS

Page 50: RESTful Web Services

Status Codes

Page 51: RESTful Web Services
Page 52: RESTful Web Services
Page 53: RESTful Web Services
Page 54: RESTful Web Services
Page 55: RESTful Web Services
Page 56: RESTful Web Services
Page 57: RESTful Web Services
Page 58: RESTful Web Services
Page 59: RESTful Web Services
Page 60: RESTful Web Services

Connectedness

Page 61: RESTful Web Services

Resources Link to Each Other

Page 62: RESTful Web Services

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>

Page 63: RESTful Web Services

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" />

Page 64: RESTful Web Services

HATEOAS

Page 65: RESTful Web Services

Statelessness

Page 66: RESTful Web Services

HTTP Is Stateless

Page 67: RESTful Web Services

Every RequestHappens in Isolation

Page 68: RESTful Web Services

State Machine

Page 69: RESTful Web Services

Resource StateServer-Side

Page 70: RESTful Web Services

Application StateClient-Side

Page 71: RESTful Web Services

Transferring State

Page 72: RESTful Web Services

Every HTTP request transfers state between the application and the requested resource.

Page 73: RESTful Web Services

Resource Applicatione.g. GET

Page 74: RESTful Web Services

Resource Applicatione.g. PUT

Page 75: RESTful Web Services

Representation State Transfer

Page 76: RESTful Web Services

Representation State TransferI see what you did there…

Page 77: RESTful Web Services

Richardson Maturity Model

Page 78: RESTful Web Services

Plain Old XMLLevel Zero

Page 79: RESTful Web Services

ResourcesLevel One

Page 80: RESTful Web Services

HTTP VerbsLevel Two

Page 81: RESTful Web Services

HypermediaLevel Three

Page 82: RESTful Web Services

Strive for Level Three

Page 83: RESTful Web Services

Be OK with Level Two

Page 84: RESTful Web Services

Be Embarrassed by Level One

Page 85: RESTful Web Services

Die in a Fire for Level Zero