How to implement bulk operations in RESTful API designs

Source: Internet
Author: User
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)

GETIt'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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.