I am developing a REST API using JSON API as the standard format for request and response data, but struggling to decide on a format for the data returned by the Hompage / Billboard page, ie: when the consumer visits http://api.example.com/.
The goal is to display the next available steps that the consumer can take, which for this example are /people and /products, and below is the best I could come up with in terms of presenting this data:
{
"links": {
"self": "http://api.example.com"
},
"data": [
{
"type": "Link",
"id": "people",
"attributes": {
"id": "people",
"href": "http://api.example.com/people"
}
},
{
"type": "Link",
"id": "products",
"attributes": {
"id": "products",
"href": "http://api.example.com/products"
}
}
]
}
I am not entirely keen on this as it feels like the data being returned fits better within the top level “links”, however according to the specification we must have at least a “data” or “meta” element, so I went with “data”. This means I am required to include some superfluous information (id, type and attributes), when all I really want to include is a “self” link with the relevant href.
I would love to hear some alternative solutions on how to solve this one!
Update:
I have since found some other topics, and it appears as though this is still officially ‘unanswered’ in the JSON API specification: