Hi,
My team and I have ran into an issue with included resources that we would appreciate some advice on.
We have some resources that have “to-many” relationships that can run into the hundreds and for performance reasons we think it best to implement a strategy that restricts the number of included resources that can be returned in a response.
Here are the solutions we have came up with:
- Set a hard limit (x) in the API. The rationale is that if more than the x resources are needed they can follow the related link which supports pagination.
- For example, if we set the limit to 25, in the below response there could only be a maximum of 25 entries in the relationships.testpoints.data array regardless of the actual number for that test. In order to indicate that there are more than 25 testpoints we discussed adding a meta object with the count in it.
- In this case there would be a testpoints.meta object containing pagination but we aren't sure how to go about it.
{“data”:[
{“type”: “test”
“id”: “test1”
“attributes”: {
“date”: “2015-11-17 11:25:00”,
“unit_tested”: “unit1”,
“tester_id”: “1234”,
“results”: “Pass”,
…
},
“relationships”: {
“testpoints”: {
“links”: {“related”: “http://url.com/v1/test/1/testpoints”},
“data”: [
{“type”: “testpoint”, “id”: “tp1”},
{“type”: “testpoint”, “id”: “tp2”},
{“type”: “testpoint”, “id”: “tp3”},
…
{“type”: “testpoint”, “id”: “tpx”}
]
},
“uut”: {
“links”: {“related”: “http://url.com/v1/uuts/unit1”},
“data”:
}
},
“links”: {“self”: “http://url.com/v1/tests/1”}
},
…
],
“included”:[
{“type”: “testpoint”,
“id”: “tp1”
“attributes”: {
“number”: 1,
“value”: 0.1,
…
}},
{“type”: “testpoint”,
“id”: “tp2”
“attributes”: {
“number”: 2,
“value”: 0.2,
…
}},
{“type”: “testpoint”,
“id”: “tp3”
“attributes”: {
“number”: 3,
“value”: 0.3,
…
}},
…
{“type”: “testpoint”,
“id”: “tpx”
“attributes”: {
“number”: x,
“value”: x.x,
…
}}
],
“meta”: {
“pagination”: {
“page_number”: 1,
“page_size”: 10,
“page_count”: 37,
“total_count”: 364,
“previous_page”: null,
“next_page”: 2,
“previous_href”: null,
“next_href”: “http://url.com/v1/tests?include=testpoint&pagenumber=2&pagesize=10”
},
“links”: {“http://url.com/v1/tests?include=testpoint”}
}
}