rest-something-different (2011-05-12)

61
REST Mike Amundsen @mamund

Upload: jun-wang

Post on 20-May-2015

450 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: REST-something-different (2011-05-12)

REST

Mike Amundsen

@mamund

Page 2: REST-something-different (2011-05-12)

Preliminaries

• Mike Amundsen

• Developer, Architect, Presenter

• Hypermedia Junkie

• “I program the Internet”

• Designing Hypermedia APIs with Node and HTML5 O’Reilly, Fall 2011

Page 3: REST-something-different (2011-05-12)

And now for something

a completely different…

Page 4: REST-something-different (2011-05-12)

Representational

State

Transfer

Page 5: REST-something-different (2011-05-12)

Representational

State

Transfer

Page 6: REST-something-different (2011-05-12)
Page 7: REST-something-different (2011-05-12)
Page 8: REST-something-different (2011-05-12)
Page 9: REST-something-different (2011-05-12)

REST

is a

style

Page 10: REST-something-different (2011-05-12)

REST

is a

style

of

network

architecture.

Page 11: REST-something-different (2011-05-12)
Page 12: REST-something-different (2011-05-12)
Page 13: REST-something-different (2011-05-12)
Page 14: REST-something-different (2011-05-12)

HTTP

is a

Standard

Page 15: REST-something-different (2011-05-12)

HTTP

is a

Standard

Transfer

Protocol

Page 16: REST-something-different (2011-05-12)

REST != HTTP

Page 17: REST-something-different (2011-05-12)

Well then, what IS REST?

Page 18: REST-something-different (2011-05-12)

Roy T. Fielding, 2000

Page 19: REST-something-different (2011-05-12)

“REST is a coordinated set of

architectural constraints that

attempts to minimize latency

and network communication

while at the same time

maximizing the independence

and scalability of component

implementations.”

Roy T. Fielding, 2000

Page 20: REST-something-different (2011-05-12)

“REST is a coordinated set of

architectural constraints that

attempts to minimize latency

and network communication

while at the same time

maximizing the independence

and scalability of component

implementations.”

Roy T. Fielding, 2000

Page 21: REST-something-different (2011-05-12)

“REST is a coordinated set of

architectural constraints that

attempts to minimize latency

and network communication

while at the same time

maximizing the independence

and scalability of component

implementations.”

Roy T. Fielding, 2000

Page 22: REST-something-different (2011-05-12)

“REST is a coordinated set of

architectural constraints that

attempts to minimize latency

and network communication

while at the same time

maximizing the independence

and scalability of component

implementations.”

Roy T. Fielding, 2000

Page 23: REST-something-different (2011-05-12)

Srsly?

Page 24: REST-something-different (2011-05-12)

But some people say…

Page 25: REST-something-different (2011-05-12)

REST IS…

• Crafting URIs

• Identifying Resources

• Designing Responses (JSON, XML, etc.)

• HTTP Verbs (GET, PUT, POST, DELETE)

• Headers (Caching, etc.)

• HTTP Response Codes (200, 404, 418, etc.)

Page 26: REST-something-different (2011-05-12)

REST IS…

• Crafting URIs

• Identifying Resources

• Designing Responses (JSON, XML, etc.)

• HTTP Verbs (GET, PUT, POST, DELETE)

• Headers (Caching, etc.)

• HTTP Response Codes (200, 404, 418, etc.)

Page 27: REST-something-different (2011-05-12)

Actually…

Page 28: REST-something-different (2011-05-12)

REST IS NOT…

• Crafting URIs

• Identifying Resources

• Designing Responses (JSON, XML, etc.)

• HTTP Verbs (GET, PUT, POST, DELETE)

• Headers (Caching, etc.)

• HTTP Response Codes (200, 404, 418, etc.)

Page 29: REST-something-different (2011-05-12)

But really, what is REST?

Page 30: REST-something-different (2011-05-12)

A set of constraints.

Page 31: REST-something-different (2011-05-12)

Client-Server

Not Peer-to-Peer

Page 32: REST-something-different (2011-05-12)

Stateless

No Server-Side Session

Page 33: REST-something-different (2011-05-12)

Cache

Don’t hit server every time

Page 34: REST-something-different (2011-05-12)

Uniform Interface

Same API for everyone

Page 35: REST-something-different (2011-05-12)

Layered System

Add hardware any time

Page 36: REST-something-different (2011-05-12)

Code On Demand *

Don’t hard-code clients, send code to them.

Page 37: REST-something-different (2011-05-12)

"I have never been

forced to accept

compromises but I have

willingly accepted

constraints."

Charles Eames,

Eames Design, 1989

Page 38: REST-something-different (2011-05-12)

Why constraints?

Page 39: REST-something-different (2011-05-12)

Is

there

anything

more

intimidating…?

Page 40: REST-something-different (2011-05-12)

Wait, that’s it?

Page 41: REST-something-different (2011-05-12)

Well…

Page 42: REST-something-different (2011-05-12)

"[REST] is achieved by

placing constraints on

connector semantics where

other styles have focused

on component semantics."

Roy T. Fielding, 2000

Page 43: REST-something-different (2011-05-12)

"[REST] is achieved by

placing constraints on

connector semantics where

other styles have focused

on component semantics."

Roy T. Fielding, 2000

Page 44: REST-something-different (2011-05-12)

"[REST] is achieved by

placing constraints on

connector semantics where

other styles have focused

on component semantics."

Roy T. Fielding, 2000

Page 45: REST-something-different (2011-05-12)

Connector != Component

Page 46: REST-something-different (2011-05-12)

Component

• Database

• File System

• Message Queue

• Transaction Manager

• Source Code

Page 47: REST-something-different (2011-05-12)

Component == Private

Page 48: REST-something-different (2011-05-12)

Connector

• Web Server

• Browser Agent

• Proxy Server

• Shared Cache

Page 49: REST-something-different (2011-05-12)

Connector == Public

Page 50: REST-something-different (2011-05-12)

Client Server Connectors

Components

The Web

Page 51: REST-something-different (2011-05-12)

And the best way to

ensure

Connectors

work together is…

Page 52: REST-something-different (2011-05-12)

Uniform Interface

1. Identification of Resources

2. Resource Representations

3. Self-Descriptive Messages

4. Hypermedia

Page 53: REST-something-different (2011-05-12)

Uniform Interface

1. Identification of Resources (URIs)

2. Resource Representations

3. Self-Descriptive Messages

4. Hypermedia

Page 54: REST-something-different (2011-05-12)

Uniform Interface

1. Identification of Resources (URIs)

2. Resource Representations (Media-Types)

3. Self-Descriptive Messages

4. Hypermedia

Page 55: REST-something-different (2011-05-12)

Uniform Interface

1. Identification of Resources (URIs)

2. Resource Representations (Media-Types)

3. Self-Descriptive Messages (Header+Body)

4. Hypermedia

Page 56: REST-something-different (2011-05-12)

Uniform Interface

1. Identification of Resources (URIs)

2. Resource Representations (Media-Types)

3. Self-Descriptive Messages (Header+Body)

4. Hypermedia (Links & Forms)

Page 57: REST-something-different (2011-05-12)

Seems kinda complicated…

Page 58: REST-something-different (2011-05-12)

REST in one slide

Read the dissertation, really!

Page 59: REST-something-different (2011-05-12)

Client Server Connectors

Components

The Web

Component Connector Connector Component

Page 60: REST-something-different (2011-05-12)

“Those of us who have been trained

as architects have this desire perhaps

at the very center of our lives: that

one day, somewhere, somehow, we

shall build one building which is

wonderful, beautiful, breathtaking, a

place where people can walk and

dream for centuries.”

Christopher Alexander,

The Timeless Way of Building - 1979

Page 61: REST-something-different (2011-05-12)

REST

Mike Amundsen

@mamund