Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.js: Multiple delete with 1 request

Tags:

backbone.js

I have a backbone.js application connecting to a REST API. I noticed that if you delete multiple models at once, seperate API request have to be sent for each model.

Is there any way to handle the delete request using 1 request?

like image 273
Xerri Avatar asked Oct 07 '22 04:10

Xerri


1 Answers

You would need your server to expose an endpoint for deleting multiple models at once by passing IDs of the models to be deleted in the first place. If you have this available the common way to handle that would be to add a method to your collection called something along the lines of deleteByIds which would accept array of IDs and then this method would remove the models from the collection on successful delete request (if sync) or straight away before sending the delete request to the API endpoint which would make sure they are all removed from the server.

By default that's how RESTful interfaces work and batch processing is always a custom extension to RESTful interfaces so there is no out of the box way to do that and it might involve you doing some extra work both on the backbone client and on the backend.

like image 73
Tom Tu Avatar answered Oct 10 '22 02:10

Tom Tu