being in a state of rest
DESCRIPTION
A Quick walkthrough the Richardson REST Maturity Model with simple examples, followed by design considerations for building software for a REST architectural style. Key point: REST is the starting position, not the end point when designing.TRANSCRIPT
![Page 1: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/1.jpg)
being in a state of RESTAslam Khan@aslamkhn
![Page 2: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/2.jpg)
What’s not on the agenda
sniper shots
grenades strapped to chest rants
mass hypnosis
![Page 3: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/3.jpg)
Let’s take a few steps back
![Page 4: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/4.jpg)
I did do this...create quote
quoteservice
POST /quoteService<QuoteRequestMessage ...
200 OK<Quote ...
![Page 5: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/5.jpg)
and this … accept quote
quoteservice
POST /quoteService<AcceptQuoteMessage ...
200 OK<StatusMessage ...
![Page 6: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/6.jpg)
and this … exceptions
quoteservice
POST /quoteService<AcceptQuoteMessage ...
200 OK<Error ...
![Page 7: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/7.jpg)
slinging XMLRPC == true
REST == false
REST(0)
no uniformity => accidental complexity
quoteservice
POST /quoteService<QuoteRequestMessage ...
200 OK<Quote ...
quoteservice
POST /quoteService<AcceptQuoteMessage ...
200 OK<StatusMessage ...
quoteservice
POST /quoteService<AcceptQuoteMessage ...
200 OK<Error ...
![Page 8: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/8.jpg)
We should use
standards, right?
![Page 9: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/9.jpg)
do contract firstxml schema + wsdl + soap + ...
enter WS_*
feels like static typing in a dynamic world
ptaaanngg!! ... oops … sniper shot
![Page 10: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/10.jpg)
slinging XMLwith envelopes
Complex remote access protocol
WS-*
toolsets are symptomatic of the complexity
quoteservice
POST /quoteService<QuoteRequestMessage ...
200 OK<Quote ...
quoteservice
POST /quoteService<AcceptQuoteMessage ...
200 OK<StatusMessage ...
quoteservice
POST /quoteService<AcceptQuoteMessage ...
200 OK<Error ...
![Page 11: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/11.jpg)
This is not my idea of software development
![Page 12: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/12.jpg)
Next attempt … many endpointsPOST /customer/176202?fromDate...
200 OK<Quote id="Q91827"
/customer
/quote
POST /quote?ref=Q91827
200 OK<Policy...
![Page 13: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/13.jpg)
same thing … just friendlyPOST <FindQuote fromDate="...
200 OK<Quote id="Q91827"
/customer/176202
/quote/Q91827
POST <AcceptQuote
200 OK<Policy...
![Page 14: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/14.jpg)
but I can almost imagine the modelcustomer
quote
findQuote(...)
accept(...)policy
*
![Page 15: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/15.jpg)
resourcesaddressability
REST(1)
oo-ish but no uniformity
![Page 16: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/16.jpg)
GET /customer/176202/quotes?from...
200 OK<Quote id="Q91827"
/customer
/quote
POST /quote/Q91827<Acceptance ...
201 OKLocation: /policy/PX81730Z9...<Policy id="PX81730Z9...
How about this … verb idioms
![Page 17: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/17.jpg)
Predictability is more important than
POST
PUT
DELETE
create
update
delete
don’t be dogmatic, be pragmatic
think safe vs unsafe and side-effects
GET retrieve
![Page 18: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/18.jpg)
Again, being predictable
201
409
401
created
conflict
unauthorised
uniformity is a powerful force
... ...
![Page 19: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/19.jpg)
HTTP Verbs+response codes
REST(2)
uniformity + unsafe vs safe operationsbut dumping a ton of URI’s on your friends is not very nice
![Page 20: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/20.jpg)
This is the next stepGET /customer/176202
200 OK<Customer id="Q91827" ... <links> <link rel='find quotes' uri='/quotes/176202"/> <link rel='policy' uri='/policy/PX81730Z9"/>
/customer
![Page 21: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/21.jpg)
and so on ...GET /quotes/Q91827
200 OK<Quotes customer="176202" ... <quote id="Q91827" <links> <link rel='accept quote' uri='/blahblah?id="Q91827"/> <link rel='cancel quote' uri='/ushoqwbyw/198n392/>
![Page 22: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/22.jpg)
state changed?GET /quotes/Q91827
200 OK<Quotes customer="176202" ... <quote id="Q91827" <links> <link rel="self" uri='/quote/Q91827"/> </link>
![Page 23: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/23.jpg)
Hypermedia(HATEOS)
REST(3)
HTTP idioms + media-types + hypermedia
![Page 24: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/24.jpg)
REST(1)
REST(2)
REST(3)
REST(0)
vanilla Rails somewhere here}Richardsonmaturity model
![Page 25: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/25.jpg)
this is the signal
in the noise!
But it is always about design.
How do you design when REST
is your architectural style?
REST is not the end goal, it is
actually your starting position.
And it’s not for everything.
![Page 26: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/26.jpg)
REST(1)
REST(2)
REST(3)
REST(0)
This is a
design choice.ranges from exploiting HTTP
to honoring HTTP
![Page 27: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/27.jpg)
Some context first
Design, for me, is just answering two questions.
1. Does that thing express its intention?
2. Where should I put that thing?
![Page 28: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/28.jpg)
5 Design things to think about
![Page 29: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/29.jpg)
resource overloading is not reuse
doubling up a resource to serve more than
its single purpose is more likely to introduce
accidental complexity than visible benefit.
there is no cost to having lots of resources(if there is, you have a bigger problem)
+
the set of resources is open ended
![Page 30: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/30.jpg)
Refer to self is importantPOST /customer<customer> ... </customer>
reduce URI explosions
200 OK<customer id=194839> ... <links> <link rel=”self” uri=”/customer/194839> </links></customer>
no need to expose /customer/{customer_id}
![Page 31: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/31.jpg)
Jou ma se State!
app state can be inferred
customer
quote
findQuote(...)
accept(...)policy
*
domain state resource state application state
![Page 32: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/32.jpg)
Search
/policy /claim /customer
Find all resources where
there is an email address
Find all claims that are
approved but unpaid and
where the policy is paid up
create another resource for the result … and then?
![Page 33: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/33.jpg)
Domain : Resource Impedancevehicle
movement*
position
{ registration : Ca28382, last_movement: { odo: 78282, lat: ... } links { ... }}
GET /lastmovement/CA28382
?
aggregates ==
resources?not necessarily
entities == resources?it is still a bi-directional mapping
problemno domain model?where should we model
behavior?
![Page 34: Being in a State of REST](https://reader033.vdocument.in/reader033/viewer/2022052901/556446ead8b42ad6268b4910/html5/thumbnails/34.jpg)
def valuable?(signal, noise)(signal.power/noise.power) > 1
end
valuable?(hype, design).should == falsevaluable?(design, hype).should == true
obligatory ruby code slide
Thanks, and so long