Grouping end point criteria

When the end point http://localhost/movies is hit, it should return movies grouped by genre. Lets assume (only in this case) a movie has one genre.

Was looking at http://jsonapi.org/format/#fetching-filtering

Should the end point, instead, look like this: http://localhost/movies?filter=grouped-by-genre

Or is there a different url structure I should consider.

Looking forward to your thoughts.

if it’s going to be grouped by genre in every case, then I would consider just making /movies do it, personally.

It won’t be in every case.

Sometimes the client will need to get movies regardless of any grouping.

I’m not sure what you mean by “grouped by”. JSON API just supports returning an array of resources; if you want to group those resources, you have to do that on the client-side. You can filter by genre, i.e. only get resources in your response that are of a certain genre(s), but that’s not the same as grouping.

You could also do GET /genres?include=movies. Each resource object in the primary data of this response would be a genre that has a relationships.movies.data property, and the movies themselves would be in included. This gives you the grouping you want.

It’s a bit six of this half-a-dozen-of-the-other, but I wanted to point out the option.