More REST less ROT (2011-06)
-
Upload
jun-wang -
Category
Technology
-
view
439 -
download
2
Transcript of More REST less ROT (2011-06)
Mike Amundsen
@mamund
“You can't cross the sea merely by standing and staring at
the water.”
- Rabindranath Tagore
Mike Amundsen
Presenter, Architect, Programmer
Current focus: “Hypermedia”
New book coming…
Designing Hypermedia APIs
w/ HTML5 and NodeJS
– O’Reilly, late 2011
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
Non-Goals
Explain the HTTP Protocol
Defend the REST Style
Promote/Denigrate any
Platform/OS
Programming Language
Web Library or Framework
My Hidden Agenda
When I get done,
I hope there will be…
Less of this…
More of this…
“Vision without action is a daydream. Action without vision
is a nightmare.”
– Japanese Proverb
ROT
Representational
Object
Transfer
Representational
Object
Transfer
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
Why is this bad?
It’s a Web “anti-pattern”
Wait, it’s a what?
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
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
On the Web, ROT
is ineffective
and/or
counterproductive
Object Serialization
Type Marshaling
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
On the Web,
ROT doesn’t scale
This is NOT an HTTP Problem
This is the nature of
distributed networks
Some examples please….
Schema Publishing ROT
Type Hints in the Payload ROT
URI Construction ROT
Object-Based Media Types ROT
They all suffer from
the same shortcoming
They try to solve
the wrong problem
"How can a server
successfully export it's private
objects in a way that
clients can see and use
them?"
Not the correct question…
"How can
a server and client share a
common understanding of
the payloads passed between
them?"
Much better question…
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
“Freedom lies in being bold.”
- Robert Frost
REST
Representational
State
Transfer
Representational
State
Transfer
State
“In computer science and automata theory,
a state is a unique configuration of
information in a program or machine.”
- Wikipedia
“State” is not an object.
The “Type-less” Web
The Web has no local “types”
The Web doesn’t need any.
The Web has payloads
Message
Metadata
We share the “state” of an app,
not the objects on the server.
Ok, how do we share “state”?
We pass messages…
That’s it?
Well…
Not just “any” messages…
We share “state” on the Web
using a “media type”
Media Types
text/html, application/xml, application/json, etc
Elements, attributes, properties, arrays, etc.
Structured, well-formed, valid, etc.
Independent of
Platform
Language
Framework
Actually, there is a
special group of media types
that are “best” for the Web…
Hyper-media Types.
Hypermedia Types
Not just “what”
name, email, price, size, …
Also “how”
a, link, img, form, input, …
Hypermedia messages
contain H-Factors
H-Factors
Servers include these to tell clients what
they can do next…
Link Factors
Control Factors
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”]
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”]
On the Web,
we share understanding
using media-types.
What do we understand?
What do we understand?
What do we understand?
What do we understand?
So we must design
the messages we share…
Design and Share Messages
Where is the data?
Where are the links?
How can I send queries?
How can I modify data?
And we must document the
design…
And create servers that
understand the media type…
And write clients that
understand the media type…
That’s how the Web is meant
to be played!
“The important thing is not to stop questioning.”
- Albert Einstein
Stop Marshaling Types
Start Using Hypermedia
Start Designing Messages
Give us Less ROT and More REST
Enjoy the Benefits of the Web!
Mike Amundsen
@mamund