Reputation: 14685
I have been happily trying HATEOAS for the first time, with a Web App that suits really well because the user navigates through a tree of "nodes".
Each time the user clicks on a link to a node, the server returns the data for that node and the server URL for the data for the related notes.
HATEOAS response body:
{"description":"A good node!",
"category":"IDEAL",
"placement":"Q16","
"_links":{"self":{"href":"http://localhost:8081/position?id=393"}},
"_embedded":{
"parent":
{"placement":"root","category":"IDEAL","_links":{"self":{"href":"http://localhost:8081/position?id=384"}}},
"next_nodes":[
{"placement":"Q13","category":"GOOD","_links":{"self":{"href":"http://localhost:8081/position?id=362"}}}
{"placement":"J10","category":"BAD","_links":{"self":{"href":"http://localhost:8081/position?id=365"}}}
]}}
When the single page web app client displays the data for the node and its relationship to the other nodes, the user clicks to indicate traversal to a new node, and the web app client fetches the data from the HATEOAS supplied next server URL.
This delivers the promise of HATEOAS - the state is in the response body, as are the server URLs for the next state, so the web app client never needs to know anything other than the first root URL.
However this falls to pieces (apparently) when (obviously) the user says "I want a URL (a client URL) for this node, so I can return to it".
For the web app client using HATEOAS, the only representation available of the "current node" is the "_self" link. Which is effectively opaque.
So how do you embed that in a web-client route/link for the user to save and return to?
In my application pictured above I find myself forced to also share the position id with the web client, which is then forced to reconstruct the server URL for that position.
Is this an expected effect of HATEOAS? It seems at face value to almost completely break it, but surely there is something basic I'm missing?
Upvotes: 0
Views: 280
Reputation: 99571
I've solved this in the past by using urls such as:
https://webapplication.example.org/#http://api.example.org/some/resource
Upvotes: 1