Reputation: 1342
The example given by the Spring framework shows the full URL being given as the href: https://spring.io/understanding/HATEOAS
For example: "href": "http://localhost:8080/customer/1"
Could I use "href": "/customer/1"
if the new call is also on http:///localhost:8080?
If I include the root URL then this ties the response to the server name. If I were to move it, or change the port then the response would have to change. It provides no new information, the root URL can be inferred as it would be the same as the one made to make this call.
Is it included so that if it is passed on to another system then it would know what URL to call?
Upvotes: 0
Views: 126
Reputation: 57257
Could I use "href": "/customer/1" if the new call is also on http:///localhost:8080?
The technical term for /customer/1
is relative reference. If your context has a "base URI", then reference resolution can be used to convert a relative reference into a URI.
In HTML, there is an explicit procedure for calculating the base URI of a document.
JSON-LD also allows the base IRI to be set explicitly, but otherwise defers to the process described in RFC 3986.
Geert Jansen makes an argument that you shouldn't use relative references in your representations. I don't find his argument particularly compelling, but it's something to be aware of.
Upvotes: 2