REST Defined Creating a RESTful interface to your site
Which is better?
This …
http://tic.com/Report.aspx?
t=Sales&y=2015&m=03!
… or this …
http://tic.com/Sales/2015/3!
Why?
Reasons � SEO � Easy to type � Easy to remember � Hides implementation stack � URLs don’t have to change when the site changes. � Hackable
URLs point to resources. � Uniform ________________ locator � They don’t point to pages � So RESTful URLs are more accurate, actually
that reduces coupling
in a stateless environment …
an architectural style … REST is ...
HI, I'm Roy Fielding, the
inventor of REST.
for addressing resources …
A RESTful URL is one that conforms to all of the constraints � Separation between client and server � Stateless communication � Cacheable � A layered system � A uniform interface
A layered system has predictable parts
The usual method
Category
Thing
Action
ID
Properly RESTful url
Category
Thing
ID
(Use HTTP method as action)
The URL should act as an API
� http://tic.com/Customer/List � http://tic.com/Customer/Create � http://tic.com/Customer/Details/71 � http://tic.com/Customer/Edit/71 � http://tic.com/Customer/Delete/71 � http://tic.com/Department � http://tic.com/Employee � http://tic.com/AddToCart/17
Or better yet ...
� GET http://tic.com/Customer � POST http://tic.com/Customer � GET http://tic.com/Customer/71 � PUT http://tic.com/Customer/71 � DELETE http://tic.com/Customer/71 � GET http://tic.com/Department � GET http://tic.com/Employee � POST http://tic.com/AddToCart/17
There are certain things you can do to make a URL RESTful � Give every “thing” an ID � Link things together � Use standard methods � Communicate statelessly � Provide multiple representations
tl;dr
� RESTful urls are easier to use, therefore better � Give every “thing” an ID � Link things together � Use standard methods � Communicate statelessly � Provide multiple representations