Java Reference
In-Depth Information
In the example, there are only two elements to the array representing two posts. Each post is a
JSON object that follows the same format:
      "id": 71892,
      "title": "Best movie of 2015",
      "content": "I think the best movie of 2015 is the Golden Egg of Siam.",
As can be seen from the JSON snippet it contains an ID that identii es the post resource followed
by the post's title and content. This is the minimum that you would expect to see in a response to a
request for a post resource regardless of the maturity of the rest interface. What makes this response
special is the links element.
      "links": [
          "rel": "self",
          "href": " http://localhost:8080/rest/posts/71892",
          "method": "GET"
This is where HATEOAS comes to life. There are three parts to each link in the link array. The rel
is the relation that the href link has to the current resource. The href is a link to more resources,
and the method is the method that must be used to obtain the resource. The rel element can have
any value and does not have to follow a convention, although it is customary for 'self' rel to refer
to a link that represents more information about the current resource. In this example, it just refers
to itself. The other links refer to other users' responses to the post (replies or responses), the users
who follow the post (followers), and the user who posted the post (owner). Any resource that relates
to the principle post resource can be represented by a link in the link array.
As you can see from the example, the i rst post in the array has four links in its links array, whereas
the second has only two. This is because the second post does not have users following it or any
Providing links in this way gives the client the information it needs to navigate to further resources
and allows you to easily extend and grow the API with relatively little pain.
A good example of a well‐designed implementation of HATEOAS is the one implemented by Paypal
.com (
paypal‐rest‐payment‐hateoas‐links/) . They have used HATEOAS to allow you to build an
API that interacts with their payment system simply by following the links provide in the links
REST is an easy and well‐established approach that is not constrained by standards. Some may
argue that this is a distinct disadvantage when compared to SOAP, which is an industry standard
with its own well‐dei ned protocol and implementation rules. However, its ease of implementation
Search WWH ::

Custom Search