Adding related property
Hi, how would I need to extend your example so that the responses contains also the related property? E.g.
{ "data": {
"type":"schools",
// ...
"links":{
"self": "http://127.0.0.1:3000/schools/553f992e5e6520b322f42ef8",
"liaisons": {
"linkage": [
// ...
],
"related": "http://127.0.0.1:3000/schools/553f992e5e6520b322f42ef8/liaisons",
"self": "http://127.0.0.1:3000/schools/553f992e5e6520b322f42ef8/links/liaisons"
}
}
}}
In another issue https://github.com/json-api/json-api/issues/582 I've some questions regarding the handling on huge linkage object arrays and I'd like to use this example as base for my experiments.
Hi @nevson,
Related urls are essentially the last piece of the spec that this library doesn't fully support yet, because I'm waiting on a solution to https://github.com/json-api/json-api/issues/497 first. That will effect my implementation, since related urls also need to support the include parameter.
Adding the "related" key to the response's link objects is already possible: in the resource description's section for url templates, you just add a "related" template, like this:
urlTemplates: {
"self": "http://127.0.0.1:3000/schools/{id}",
"related": "http://127.0.0.1:3000/schools/{ownerId}/{path}"
}
The problem is, that if you actually try to load http://127.0.0.1:3000/schools/{id}/{path}, you'll get a 404 for now.
As a temporary solution, I'd suggest doing a single-level include at the resource level. That is, suppose each "schools" resource has a relationship called "students". Eventually, you'll be able to load the related students by doing: https://example.com/schools/{schoolId}/students. But, for now, you can just do https://example.com/schools/{schoolId}?include=students, and all the students will be listed under the response's "included" key
@ethanresnick Thanks for helping me out :) I'll wait then with using the related property until it's implemented in your node json-api server and stick to the include solution for now.