32
REST The Most Misunderstood Software Architecture Ever Martín Soto February 17, 2015

REST: The Most Misunderstood Software Architecture Ever

Embed Size (px)

Citation preview

Page 1: REST: The Most Misunderstood Software Architecture Ever

RESTThe Most Misunderstood Software Architecture Ever

Martín SotoFebruary 17, 2015

Page 2: REST: The Most Misunderstood Software Architecture Ever

REST● REpresentational State Transfer

● Roy Fielding, 2000

● Deeply misunderstood! Many systems (mostly APIs) claim to be REST(ful), few really are.

● Abstraction of the World Wide Web.

Page 3: REST: The Most Misunderstood Software Architecture Ever
Page 4: REST: The Most Misunderstood Software Architecture Ever

Richardson’s REST Maturity Model

http://martinfowler.com/articles/richardsonMaturityModel.html

Page 5: REST: The Most Misunderstood Software Architecture Ever

Level 0: Plain, Old RPC

http://martinfowler.com/articles/richardsonMaturityModel.html

Plain, Old Remote Procedure Call (RPC)

Page 6: REST: The Most Misunderstood Software Architecture Ever

Level 0: Remote Procedure Call (RPC)

Caller Callee

Procedure call

Return value

Caller execution

Caller continues

Procedure execution

Netw

ork

CorbaDCOMjava RMI...

HTTP

Level 0

Page 7: REST: The Most Misunderstood Software Architecture Ever

Level 0: RPC over HTTP

● Only one URL (e.g., http://example.com/api/v1)

● Procedure name and parameters passed as request payload.

● Return value returned as response.

Page 9: REST: The Most Misunderstood Software Architecture Ever

Level 1: Resources

http://martinfowler.com/articles/richardsonMaturityModel.html

Page 10: REST: The Most Misunderstood Software Architecture Ever

Level 1: Resources

Company 1

Company 7

Company 33

User 4

User 28

User 13 User 5

User 62

User 44

User 99

User 63

Security policy 22

Security policy 85

http://api.com/companies/1

http://api.com/users/63

http://api.com/policies/85

http://api.com/companies/33

http://api.com/companies/7

http://api.com/users/63http://api.com/users/63

http://api.com/users/63

http://api.com/users/63

http://api.com/users/63

http://api.com/users/63

http://api.com/users/63

http://api.com/policies/85

Page 11: REST: The Most Misunderstood Software Architecture Ever

Level 2: HTTP Verbs

http://martinfowler.com/articles/richardsonMaturityModel.html

Page 12: REST: The Most Misunderstood Software Architecture Ever

Level 2: HTTP Methods

POST Create new resource (when POSTing to a collection) or execute especial operation on resource.

GET Read the contents of resource (the resource representation)

PUT Upload new resource contents replacing any previous contents. Also, create a resource if previously nonexistent.

DELETE Delete the resource.

Page 14: REST: The Most Misunderstood Software Architecture Ever

But…The Web is

interconnected...

Page 15: REST: The Most Misunderstood Software Architecture Ever

It’s the hypertext,

stupid!

Page 16: REST: The Most Misunderstood Software Architecture Ever

Hypertext: HTML

<HTML>

<HEAD>

<TITLE>Your Title Here</TITLE>

</HEAD>

<BODY BGCOLOR="FFFFFF">

<CENTER><IMG SRC="clouds.jpg" ALIGN="

BOTTOM"> </CENTER>

<HR>

<a href="http://somegreatsite.com">Link

Name</a>

is a link to another nifty site

<H1>This is a Header</H1>

<H2>This is a Medium Header</H2>

Send me mail at <a href="mailto:

[email protected]">

[email protected]</a>.

<P> This is a new paragraph!

<P> <B>This is a new paragraph!</B>

<BR> <B><I>This is a new sentence without

a paragraph break, in bold italics.

</I></B>

<HR>

</BODY>

</HTML>

Page 17: REST: The Most Misunderstood Software Architecture Ever

Level 3: Hypermedia

http://martinfowler.com/articles/richardsonMaturityModel.html

Page 18: REST: The Most Misunderstood Software Architecture Ever
Page 19: REST: The Most Misunderstood Software Architecture Ever

HATEOASHypertext As The

Engine of Application State

Page 20: REST: The Most Misunderstood Software Architecture Ever

“What needs to be done to make the REST architectural style clear on the notion that hypertext is a constraint?

In other words, if the engine of application state (and hence the API) is not being driven by hypertext, then it cannot be RESTful and cannot be a

REST API. Period. Is there some broken manual somewhere that

needs to be fixed?

Roy Fielding

http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven

Page 21: REST: The Most Misunderstood Software Architecture Ever

Programming with Hypermedia?

http://martinfowler.com/articles/richardsonMaturityModel.html

??? ???

Page 22: REST: The Most Misunderstood Software Architecture Ever

Hypermedia for Data APIs

The Web<HTML>

<HEAD>

<TITLE>Your Title Here</TITLE>

</HEAD>

<BODY BGCOLOR="FFFFFF">

<CENTER><IMG SRC="clouds.jpg" ALIGN="BOTTOM"> </CENTER>

<HR>

<a href="http://somegreatsite.com">Link Name</a>

is a link to another nifty site

<H1>This is a Header</H1>

<H2>This is a Medium Header</H2>

...

Data APIs

?

Page 23: REST: The Most Misunderstood Software Architecture Ever

Example

Putting Hypermedia to Good Use: Regional Privacy

EU Web Service

US Web Service CN Web

Service

Page 24: REST: The Most Misunderstood Software Architecture Ever

What we got from hypermedia

API is independent of data locationWe were able to introduce this structure without breaking our API contract: Resource location becomes an implementation detail

Data privacy becomes evidentCustomers can verify where their data is located by just looking at the requests their clients are running.

All customers can be handled equallyAs long as you stick to a format, you can serve it from wherever you like and clients will handle it.

APIVersioningWe can evolve the API by providing new fields pointing to new resources or formats. As long as the older fields are preserved, older clients will continue to work.

Page 25: REST: The Most Misunderstood Software Architecture Ever

Example

Federated Systems: Initial System

Relational DB (MySQL)

Page 26: REST: The Most Misunderstood Software Architecture Ever

Example

Federated Systems: Fast Caching

Relational DB (e.g., MySQL)

Key-value Store (e.g., Redis)

Page 27: REST: The Most Misunderstood Software Architecture Ever

Example

Federated Systems: Microservices

Microservice 1

Microservice 2

Microservice 3

Page 28: REST: The Most Misunderstood Software Architecture Ever

Example

Federated Systems: SaaS

Customer 1 Customer 2

Customer 3

High-capacity cloud instance

Low-capacity cloud instance

In-premise, dedicated hardware

Page 29: REST: The Most Misunderstood Software Architecture Ever

The (Not-So-Exiting) Present

● Many more APIs are going the hypermedia wayGitHub, Nike, PayPal.

● Documentation for popular APIs still specifies URLsAPI providers make resource locations part of the API contract probably to appease programmers.

● Server frameworks and client libraries are getting better at hypermediaThe improvement has been significant in the last two or three years.

Page 30: REST: The Most Misunderstood Software Architecture Ever

Wrap Up

Page 31: REST: The Most Misunderstood Software Architecture Ever

Thanks!...and welcome to the discussion

Martín Soto@msotoweb

[email protected]

http://martinsoto.co