How do I implement bulk operations in RESTful API designs? For example, a request to delete n IDs, similar to Elasticsearch in bulk that design.
Reply content:
How do I implement bulk operations in RESTful API designs? For example, a request to delete n IDs, similar to Elasticsearch in bulk that design.
There are many ways to design, borrowing Backbone.js's argument: there's more Than one means to do It, don't be too tangled.
To put it simply, here are a few good things:
GET /ec2/instance/batch?id=aa,bb,cc
: Simple Design
GET /ec2/instance?batch={"ids":["aa","bb","cc"]}
: Robust Design
GET /ec2/instance?batch=[{"method":"DELETE","id":"aa"},{"method":"DELETE","id":"bb"},{"method":"DELETE","id":"cc"}]
: Facebook design (outside the wall)
GET
It's no problem to change all of the above POST
.
When you design batch, you don't have to be too obsessed with RESTful definitions (at least I think), after all, things that exist to optimize performance.
The bulk operation is mainly JS operation, after obtaining multiple IDs, the ID collection is sent to an action with Ajax, and the action is written in action.
As an example, routes can write this
resources :shops do collection do post :association_shops endend
http://api.taobao.com/apidoc/api.htm?path=cid:4-apiId:315
http://backbonejs.org/#FAQ-tim-toady
Https://www.npmjs.org/package/restful-api
Search for batch on these two pages