REST and Hyper Media
HATEOAS about State and transition between states
Rest
"Root"
"/" Links {[
{ Rel."Create Post" Href-"/logs/" }
….
}]
Item = [
Blog:
Rel: Delete
Rel:Published
Blog:
Rel:UnPublished
]
HyperMedia is the state
Allows the server to change the contract without need the client
Best to have one implied verb to url.
Example: Mash Up of multiple blogs
Entries {[
{ rel: "get","blogger.com/blog/5/3/2011/cool_slug.html"},
{ rel: "get","my_blog.com/may/cool_slug.html"},
...
]}
Http Codes
1XX - Did nothing
2XX - Everything worked
3XX - Something wrong with the resource it is your fault
4XX - Something wrong with the resource on the server
5XX - Server error
Odata - is one why to handle this.
Entry point
/$metadata
On each item will have __metadata (JSON example)
Forms are an approach to linking that allows the server to guide the client on how to use the link to transition to the next state.
With this approach, each link is a GET that returns an electronic form. That form specifies Url, Method as well as pre-filled information from the server such as Item details. The form may also specify required fields such as a Quantity field.
Advantage of forms is it allows the client to be less coupled to knowledge of links which yields greater evolvability.
For example when adding item '1' to a shopping cart, the client may see a link such as the following.
<link rel="rc:AddItem" url="/restcart/forms/additem/1" />
The client then automatically does a GET on the link and retrieves an AddItem form that looks like the following.
<form>
<url>/restcart/cart/12456</url>
<method>POST</method>
<mediatype>vnd-restcart+xml</mediatype>
<item>
<productNo>1</itemNo>
<description>An item</description>
<price>$19.95</price>
<sku>123456789</sku>
</item>
<required>
<quantity>1</quantity>
</required>
</form>
This form offers the client everything it needs to move forward. It does not have to build up the item information to POST as it has already been sent by the server. The server also specifies the media type for the client to use. This form additional specifies that the client must provide a quantity.
To move forward, the client will POST to the specified url using the included item as the body. As required fields are specified, the client must supply those as well.
The server can also embed a token in the response in order to ensure the price of the item is valid for a period of time (say 2 hours). If there is no such guarantee or the time has expired, the server can return a status 409 to the client indicating that it needs to refresh the form.
*Note: There are alternative approaches to exposing the cart as a resource, for example the CART state could be maintained on the client and sent with the POST. In either case it would not rely on session state.
Links
Comments (0)
You don't have permission to comment on this page.