lux icon indicating copy to clipboard operation
lux copied to clipboard

Built-In Nested Relationship Routes

Open nickschot opened this issue 8 years ago • 6 comments

Seems to be mandatory in JSON-API, but isn't currently working.

See: http://jsonapi.org/format/#fetching-relationships

Example request:

GET /articles/1/relationships/author HTTP/1.1
Accept: application/vnd.api+json

Example response:

HTTP/1.1 200 OK
Content-Type: application/vnd.api+json

{
  "links": {
    "self": "/articles/1/relationships/author",
    "related": "/articles/1/author"
  },
  "data": {
    "type": "people",
    "id": "12"
  }
}

nickschot avatar Nov 09 '16 13:11 nickschot

I was looking for a while for the optional flag. In the end it was there....

Responses can be further refined with the optional features described below.

This can be closed then if you want :)

Though I guess it would be nice to cleanly get relationships/relationship data from URL's like (optionally) proposed:

/articles/1/relationships/author
/articles/1/author

nickschot avatar Nov 09 '16 15:11 nickschot

This would be a nice feature to have. Even if it ends up just being docs on how to implement these routes manually.

zacharygolba avatar Nov 09 '16 19:11 zacharygolba

This is really important for JSON:API based APIs. Not having a dedicated route for relationships becomes a scalability nightmare. For instance, say I have a Post that has 2000 comments. Using Lux currently, just requesting that one Post would also sideload all 2000 comments. It would just break down.

benkingcode avatar Jan 10 '17 17:01 benkingcode

Good point. I'm already encountering some relationships for which hundreds of entries are added to the relationship section of that record. To my understanding relationship links are not necessary anymore when a relationship URL (i.e. mymodel/1/myrelationship) is present. Should give a nice performance boost and would definitely be a great addition.

See: http://jsonapi.org/recommendations/#urls-relationships

nickschot avatar Jan 10 '17 18:01 nickschot

I agree @dbbk. This is definitely on the radar.

zacharygolba avatar Jan 10 '17 22:01 zacharygolba

I was also looking for this functionality just now. And long with it, there should be pagination support for such nested relationships, see: http://discuss.jsonapi.org/t/how-to-handle-an-excessive-number-of-included-resources/209/2

lehni avatar May 31 '17 10:05 lehni