Search code examples
restjson-api

RESTful related resource using JSONAPI schema


I am following the jsonapi schema to return a standardised response from a web API. I want to reduce the number of HTTP requests to get related information so it looks like I want to use compound documents to return (for example) an article and two related comments.

I somewhat understand this but I am wondering what the RESTful GET request would be? I am thinking something like

http://api.mysite.com/v1/articles/1?comments=2

I like to be explicit but are the request parameters necessary in order to return related information from a resource?


Solution

  • Sound like you want /v1/articles/1?include=comments&limitComments=2

    Where limitComments is an API-specific param (note member name requirements)

    http://jsonapi.org/format/#query-parameters http://jsonapi.org/format/#fetching-includes

    Alternatively, you could /v1/comments?include=articles&filter[articles]=1&page[size]=2

    See http://jsonapi.org/recommendations/#filtering and http://jsonapi.org/format/#fetching-pagination