Search code examples
hateoashypermediahal-json

What is better between one link versus an array of links?


Option 1:

Return as many links as there are resources.

{
        "teamName": "Steelers"
        "links": {
            "players": [
                { "href": "http://api.com/players/1" },
                { "href": "http://api.com/players/2" },
                { "href": "http://api.com/players/3" }
            ]
    }

It can see it being useful in the case we've already been caching some of the player resources on the client side.

Option 2:

Return a single link leading to the list of resources.

{
    "teamName": "Steelers"
    "links": {
        "players": [
            { "href": "http://api.com/teams/1/players" }
        ]
}

It looks a lot cleaner, and we can fetch the players in one request.


Solution

  • I think there is no definitive answer to that question because it depends on your use case. In first option I would add more information about player for each link for the player.