More REST less ROT (2011-06)

78
Mike Amundsen @mamund

Transcript of More REST less ROT (2011-06)

Page 1: More REST less ROT (2011-06)

Mike Amundsen

@mamund

Page 2: More REST less ROT (2011-06)

“You can't cross the sea merely by standing and staring at

the water.”

- Rabindranath Tagore

Page 3: More REST less ROT (2011-06)

Mike Amundsen

Presenter, Architect, Programmer

Current focus: “Hypermedia”

New book coming…

Designing Hypermedia APIs

w/ HTML5 and NodeJS

– O’Reilly, late 2011

Page 4: More REST less ROT (2011-06)

Goals

Identify common Web implementation

patterns

Encourage you to re-think your habits

Challenge existing frameworks & tooling

Improve the quality of information on the

Web

Page 5: More REST less ROT (2011-06)

Non-Goals

Explain the HTTP Protocol

Defend the REST Style

Promote/Denigrate any

Platform/OS

Programming Language

Web Library or Framework

Page 6: More REST less ROT (2011-06)

My Hidden Agenda

Page 7: More REST less ROT (2011-06)

When I get done,

I hope there will be…

Page 8: More REST less ROT (2011-06)

Less of this…

Page 9: More REST less ROT (2011-06)

More of this…

Page 10: More REST less ROT (2011-06)

“Vision without action is a daydream. Action without vision

is a nightmare.”

– Japanese Proverb

Page 11: More REST less ROT (2011-06)

ROT

Page 12: More REST less ROT (2011-06)

Representational

Object

Transfer

Page 13: More REST less ROT (2011-06)

Representational

Object

Transfer

Page 14: More REST less ROT (2011-06)

Object

“In computer science, an object is any

entity that can be manipulated by the

commands of a programming language,

such as a value, variable, function, or data

structure.”

- Wikipedia

Page 15: More REST less ROT (2011-06)

Why is this bad?

Page 16: More REST less ROT (2011-06)

It’s a Web “anti-pattern”

Page 17: More REST less ROT (2011-06)

Wait, it’s a what?

Page 18: More REST less ROT (2011-06)

Anti-pattern

“In software engineering, an anti-

pattern (or antipattern) is a pattern that

may be commonly used but is ineffective

and/or counterproductive in practice.”

- Wikipedia

Page 19: More REST less ROT (2011-06)

Anti-pattern

“In software engineering, an anti-

pattern (or antipattern) is a pattern that

may be commonly used but is ineffective

and/or counterproductive in practice.”

- Wikipedia

Page 20: More REST less ROT (2011-06)

On the Web, ROT

is ineffective

and/or

counterproductive

Object Serialization

Type Marshaling

Page 21: More REST less ROT (2011-06)

Type Marshaling Problems

Updates on the server can break the

clients

Objects/Members added/changed/removed

Moving to a new server/domain can

break the clients

Object IDs (URIs) added/change/removed

Modifying the process flow can break

the clients

Object processing added/changed/removed

Page 22: More REST less ROT (2011-06)

On the Web,

ROT doesn’t scale

Page 23: More REST less ROT (2011-06)

This is NOT an HTTP Problem

Page 24: More REST less ROT (2011-06)

This is the nature of

distributed networks

Page 25: More REST less ROT (2011-06)

Some examples please….

Page 26: More REST less ROT (2011-06)

Schema Publishing ROT

Page 27: More REST less ROT (2011-06)

Type Hints in the Payload ROT

Page 28: More REST less ROT (2011-06)

URI Construction ROT

Page 29: More REST less ROT (2011-06)

Object-Based Media Types ROT

Page 30: More REST less ROT (2011-06)

They all suffer from

the same shortcoming

Page 31: More REST less ROT (2011-06)

They try to solve

the wrong problem

Page 32: More REST less ROT (2011-06)

"How can a server

successfully export it's private

objects in a way that

clients can see and use

them?"

Not the correct question…

Page 33: More REST less ROT (2011-06)

"How can

a server and client share a

common understanding of

the payloads passed between

them?"

Much better question…

Page 34: More REST less ROT (2011-06)

We need to

Stop sharing private objects

Look beyond local “types” as sharing units

Make it work across:

Platforms

Languages

Frameworks

We need a

common understanding

Page 35: More REST less ROT (2011-06)

“Freedom lies in being bold.”

- Robert Frost

Page 36: More REST less ROT (2011-06)

REST

Page 37: More REST less ROT (2011-06)

Representational

State

Transfer

Page 38: More REST less ROT (2011-06)

Representational

State

Transfer

Page 39: More REST less ROT (2011-06)

State

“In computer science and automata theory,

a state is a unique configuration of

information in a program or machine.”

- Wikipedia

Page 40: More REST less ROT (2011-06)

“State” is not an object.

Page 41: More REST less ROT (2011-06)

The “Type-less” Web

The Web has no local “types”

The Web doesn’t need any.

The Web has payloads

Message

Metadata

Page 42: More REST less ROT (2011-06)

We share the “state” of an app,

not the objects on the server.

Page 43: More REST less ROT (2011-06)

Ok, how do we share “state”?

Page 44: More REST less ROT (2011-06)

We pass messages…

Page 45: More REST less ROT (2011-06)

That’s it?

Page 46: More REST less ROT (2011-06)

Well…

Page 47: More REST less ROT (2011-06)

Not just “any” messages…

Page 48: More REST less ROT (2011-06)

We share “state” on the Web

using a “media type”

Page 49: More REST less ROT (2011-06)

Media Types

text/html, application/xml, application/json, etc

Elements, attributes, properties, arrays, etc.

Structured, well-formed, valid, etc.

Independent of

Platform

Language

Framework

Page 50: More REST less ROT (2011-06)

Actually, there is a

special group of media types

that are “best” for the Web…

Page 51: More REST less ROT (2011-06)

Hyper-media Types.

Page 52: More REST less ROT (2011-06)

Hypermedia Types

Not just “what”

name, email, price, size, …

Also “how”

a, link, img, form, input, …

Page 53: More REST less ROT (2011-06)

Hypermedia messages

contain H-Factors

Page 54: More REST less ROT (2011-06)

H-Factors

Servers include these to tell clients what

they can do next…

Link Factors

Control Factors

Page 55: More REST less ROT (2011-06)

Link Factors

LE = Link Embedding

HTML.IMG

LO = Link Outbound

HTML.A

LT = Link Template

HTML.FORM[action=“get”]

LN = Link Non-Idempotent

HTML.FORM[action=“post”]

LI = Link Idempotent

HTML.FORM[action=“put”]

Page 56: More REST less ROT (2011-06)

Control Factors

CR = Control Reads

HTML.LINK[rel=“stylesheet”]

CU = Control Updates

HTML.FORM[enctype=“text/plain”]

CM = Control Methods

HTML.FORM[method=“post”]

CL = Control Links

A[rel=“payment”]

Page 57: More REST less ROT (2011-06)

On the Web,

we share understanding

using media-types.

Page 58: More REST less ROT (2011-06)

What do we understand?

Page 59: More REST less ROT (2011-06)

What do we understand?

Page 60: More REST less ROT (2011-06)

What do we understand?

Page 61: More REST less ROT (2011-06)

What do we understand?

Page 62: More REST less ROT (2011-06)

So we must design

the messages we share…

Page 63: More REST less ROT (2011-06)

Design and Share Messages

Where is the data?

Where are the links?

How can I send queries?

How can I modify data?

Page 64: More REST less ROT (2011-06)

And we must document the

design…

Page 65: More REST less ROT (2011-06)
Page 66: More REST less ROT (2011-06)
Page 67: More REST less ROT (2011-06)

And create servers that

understand the media type…

Page 68: More REST less ROT (2011-06)
Page 69: More REST less ROT (2011-06)

And write clients that

understand the media type…

Page 70: More REST less ROT (2011-06)
Page 71: More REST less ROT (2011-06)

That’s how the Web is meant

to be played!

Page 72: More REST less ROT (2011-06)

“The important thing is not to stop questioning.”

- Albert Einstein

Page 73: More REST less ROT (2011-06)

Stop Marshaling Types

Page 74: More REST less ROT (2011-06)

Start Using Hypermedia

Page 75: More REST less ROT (2011-06)

Start Designing Messages

Page 76: More REST less ROT (2011-06)

Give us Less ROT and More REST

Page 77: More REST less ROT (2011-06)

Enjoy the Benefits of the Web!

Page 78: More REST less ROT (2011-06)

Mike Amundsen

@mamund