jsonapi-datastore
jsonapi-datastore copied to clipboard
Add included objects to serialized JSON
In one of my apps using jsonapi-datastore I needed a way to include to result of serialize method an array of complete relationship objects, just like in jsonapi specification. For my purposes, I created this: mklocek/jsonapi-datastore@a955efec9ecaba87a0dde0598232d1822022df3a. Including is optional here and looks like that:
var projectAttributes = {
attributes: ['title'],
relationships: ['clients', 'managers'],
included: {
clients: {
attributes: ['name']
},
managers: {
attributes: ['name']
}
}
};
project.serialize(projectAttributes);
=> # jsonapi json containing 'included' array
Have you thought about such feature?
Hi @mklocek. jsonapi-datastore was intended as a client-side library. Hence, creating payloads with an included property was not in the requirements, as (AFAIK) only a server would have to generate those. Would you mind elaborating on your use-case?
Hi @beauby! I needed a way to create nested_form-like api requests. That's not the way things are made in jsonapi specification, just my use-case, so I didn't make PR. Just wondering if it could be a good feature for you.