Java Reference
In-Depth Information
This could be problematic if we had thousands of products to send back to our client. We
might overload it, or the client might wait forever for the response to finish downloading. We
could instead list only the first five products and provide a link to get the next set:
< products >
< link rel = "next" href = "http://example.com/store/products?startIndex=5" />
< product id = "123" >
< name > headphones </ name >
< price > $16 . 99 </ price >
</ product >
...
</ products >
When first querying for a list of products, clients don't have to know they're getting back a
list of only five products. The data format can tell them that they didn't get a full set and that
to get the next set, they need to follow a specific link. Following the next link could get
them back a new document with additional links:
< products >
< link rel = "previous" href = "http://example.com/store/products?startIndex=0" />
< link rel = "next" href = "http://example.com/webstore/products?startIndex=10" />
< product id = "128" >
< name > stuff </ name >
< price > $16 . 99 </ price >
</ product >
...
</ products >
In this case, there is the additional state transition of previous so that clients can browse an
earlier part of the product list. The next and previous links seem a bit trivial, but imagine if
we had other transition types like payment , inventory , or sales .
This sort of approach gives the server a lot of flexibility, as it can change where and how
state transitions happen on the fly. It could provide new and interesting opportunities to surf
to. In Chapter 10 , we'll dive into HATEOAS again.
Wrapping Up
REST identifies the key architectural principles of why the Web is so prevalent and scalable.
The next step in the evolution of the Web is to apply these principles to the Semantic Web
and the world of web services. REST offers a simple, interoperable, and flexible way of writ-
ing web services that can be very different than the RPC mechanisms like CORBA and WS-
* that so many of us have had training in. In the next chapter we will apply the concepts of
REST by defining a distributed RESTful interface for an existing business object model.
Search WWH ::




Custom Search