Java Reference
In-Depth Information
When a client receives a document with embedded Atom links, it looks up the relationship it
is interested in and invokes the URI embedded within the href link attribute.
Advantages of Using HATEOAS with Web Services
It is pretty obvious why links and forms have done so much to make the Web so prevalent.
With one browser, we have a window to a wide world of information and services. Search
engines crawl the Internet and index websites, so all that data is at our fingertips. This is all
possible because the Web is self-describing. We get a document and we know how to retrieve
additional information by following links. We know how to purchase something from
Amazon because the HTML form tells us how.
Machine-based clients are a little different, though. Other than browsers, there aren't a lot of
generic machine-based clients that know how to interpret self-describing documents. They
can't make decisions on the fly like humans can. They require programmers to tell them how
to interpret data received from a service and how to transition to other states in the interac-
tion between client and server. So, does that make HATEOAS useless to machine-based cli-
ents? Not at all. Let's look at some of the advantages.
Location transparency
One feature that HATEOAS provides is location transparency. In a RESTful system that
leverages HATEOAS, very few URIs are published to the outside world. Services and in-
formation are represented within links embedded in the data formats returned by accessing
these top-level URIs. Clients need to know the logical link names to look for, but don't have
to know the actual network locations of the linked services.
For those of you who have written EJBs, this isn't much different than using the Java Nam-
ing and Directory Interface (JNDI). Like a naming service, links provide a level of indirec-
tion so that underlying services can change their locations on the network without breaking
client logic and code. HATEOAS has an additional advantage in that the top-level web ser-
vice has control over which links are transferred.
Decoupling interaction details
Consider a request that gives us a list of customers in a customer database: GET /customers .
If our database has thousands and thousands of entries, we do not want to return them all
with one basic query. What we could do is define a view into our database using URI query
parameters:
/ customers ? start ={ startIndex }& size ={ numberReturned }
Search WWH ::




Custom Search