Search code examples
hateoashypermediahal-json

Is it ok to have different links leading to the same resource?


Option 1:

We always return "absolute" links (no nesting). That way we always give to the client the same link for a given resource.

{
    "employeeName": "Joe"
    "links": {
        "company": [
            { "href": "http://api.com/companies/1" }
        ]
}

Is it needed? (knowing that it requires extra work on the server side)

Option 2:

We may also return "relative" links, nested under the resource returned to the client (here employee). But now the client may have received 2 differents links ("http://api.com/companies/1" and "http://api.com/employees/4/company") corresponding to the same resource.

{
    "employeeName": "Joe"
    "links": {
        "company": [
            { "href": "http://api.com/employees/4/company" }
        ]
}

Is there a better option than the other and why?


Solution

  • It's OK to have multiple links to same resource.

    URL design is irrelevant in HATEOAS.