Comments (7)
I like this. As with #20, I suggest making it an optional feature.
from json-api.
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.
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.
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.
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.
Oh, I see now that @indirect mentions that in #20. I still think the two should be considered in combination...
from json-api.
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:
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)
- Is there any way to include not related models into a model for JsonApiFramework 2.8.0? HOT 2
- Provide JSON Schema for JSON:API 1.1 HOT 2
- Provide an updates list/blog HOT 9
- 1.1 seems to contain a breaking change - 'lid' now required for resource creation? HOT 2
- How is 'lid' actually used? The 1.1 spec says nothing about this HOT 13
- Allow custom resource links HOT 13
- Why the square bracket syntax for query params? HOT 7
- consider support for implementation-specific members HOT 2
- JSON-LD integration example HOT 1
- Clarify intent of links member HOT 1
- How does one document a JSON:API HOT 4
- 1.1 spec disallows e.g. filter[author.name] HOT 4
- Inclusion of related resources for heterogeneous collections
- PrimaryResourceType not to be null at this point HOT 1
- Create/update relationships having attributes? HOT 3
- ember-data link on implementations page is broken HOT 2
- Bulk delete as either extention or implementation HOT 4
- Extend Spec To Allow Creation of Multiple Resources in One API Call HOT 1
- Profiles should be allowed to define query parameters HOT 5
- JSONRenderer does not extract includes from PolymorphicModelSerializer properly HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-api.