Skip to content

Bulk resources create/update/delete approach #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
heyiammushu opened this issue Mar 16, 2021 · 1 comment
Closed

Bulk resources create/update/delete approach #50

heyiammushu opened this issue Mar 16, 2021 · 1 comment

Comments

@heyiammushu
Copy link

I know that it's out of the specification, at least yet, but it's kind of common thing on the backend to create/update/delete more then one resource. I've found some approaches how do people do this in borders of json api in general, but I am just curious what is the best practise to do such a superstructure in a scope of this package. I am trying to rewrite controller methods in doc specified way, and which I believe is the only way here, but it feels bad, I need to break json api payload structure for this, and I dont feel where and how I can do it safely and clean. Otherwise, the only clean way to do it in the specification style is to send one request for one resource, but is it warranted to do it like that if I need to mass update 10 resources? 10 requests? Could you please provide some info about this, I don't want to build an ugly monster here.

@lindyhopchris
Copy link
Contributor

Hi! So the JSON:API spec has recently added an Atomic Operations extension, which would allow you to do bulk create/update/delete. Details are here:
https://jsonapi.org/ext/atomic/

I do plan to support Atomic Operations, but I don't know when I'll get to them. This package is taking up a phenomenal amount of my time at the moment, and I really need to get back to real work sometime soon! But I will definitely get to Atomic Operations at some point as I want to use them in the APIs that I maintain - so I'm motivated!!

In the meantime, I tend to use Custom Actions for things that aren't defined in the spec. As these are custom things, I don't tend to use the JSON:API spec for the payload sent by the client, and instead just reply with a JSON:API payload. I.e. the request would be:

DELETE /api/v1/posts/-actions/bulk-delete
Accept: application/vnd.api+json
Content-Type: application/json

{
   ....
}

Note that by using application/json as the content type, the client payload can be any structure you want for the custom action.

Longer term Atomic Operations are the spec-compliant solution, but in the meantime this custom action approach has worked well for me.

Closing in favour of #39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants