GithubHelp home page GithubHelp logo

Requesting includes about json-api HOT 7 CLOSED

json-api avatar json-api commented on May 16, 2024
Requesting includes

from json-api.

Comments (7)

hjdivad avatar hjdivad commented on May 16, 2024

I like this. As with #20, I suggest making it an optional feature.

from json-api.

lukfugl avatar lukfugl commented on May 16, 2024

Not a duplicate with #5, since it was closed without change. But from the discussion on that issue, #5 (comment) is a good example of the most common mechanism for this "in the wild" .

from json-api.

dgeb avatar dgeb commented on May 16, 2024

In an API I have under development, I support this by allowing related records to be included with an include param. For instance:

/posts/1?include=comments

I've found that a flat listing is not always sufficient, because we may want to include relationships relative to particular related records. Let's say that you want to include the post, comments and authors of comments (but not authors of the post):

/posts/1?include=comments(authors)

Simarly, if you want to include authors of posts as well:

/posts/1?include=authors,comments(authors)

As I mentioned in #20, I have already centralized and generalized all this logic to work with AMS so that it's transparent to controllers and serializers, and I will gladly share if this approach is chosen for the spec.

from json-api.

lukfugl avatar lukfugl commented on May 16, 2024

Hmm, github relabeled the second link in my previous comment, but the second link is to a specific comment in it's discussion. :)

from json-api.

lukfugl avatar lukfugl commented on May 16, 2024

Also, related to this, in Canvas' API (https://canvas.instructure.com/doc/api/) we also use the include query parameter to toggle subsets of the resource's non-relational properties.

For example, when listing courses, including include[]=syllabus_body in the query parameters will cause the returned course documents to have a syllabus_body member. This is not a related document (in the current API; maybe it should be), but is a simple string value. However, it can be quite large, so it's advantageous to only include it in the response when explicitly requested.

I'm not holding up Canvas' API as something the needs to be (or even should be) emulated here, but when considering how we want to control conditional side-loading, we should try to keep in mind non-relational use cases.

from json-api.

lukfugl avatar lukfugl commented on May 16, 2024

Oh, I see now that @indirect mentions that in #20. I still think the two should be considered in combination...

from json-api.

GavinJoyce avatar GavinJoyce commented on May 16, 2024

A copy of my note from #5 :


Here's some examples of how I plan to use conditional side-loading with restpack-serializer. These examples model Artists -> Albums -> Songs rails app source.

Here is a collection of artists:

http://restpack-serializer-sample.herokuapp.com/artists.json

And here are just two:

http://restpack-serializer-sample.herokuapp.com/artists.json?ids=1,2

Let's side-load their albums:

http://restpack-serializer-sample.herokuapp.com/artists.json?ids=1,2&includes=albums

Now we'll side-load albums and songs:

http://restpack-serializer-sample.herokuapp.com/artists.json?ids=1,2&includes=albums,songs

Notice that as there may be a large number of songs (there are 31 in this case), we're only returning the first page here. I plan to add links to additional pages in the meta data, the URLs will take the following form:

http://restpack-serializer-sample.herokuapp.com/songs.json?artist_ids=1,2&page=2

or if we want to include side-loads:

http://restpack-serializer-sample.herokuapp.com/songs.json?artist_ids=1,2&page=2&includes=artists,albums

I plan to implement some of the json-api draft in the coming days so expect the JSON output to become more familiar soon.

from json-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.