Settings

Theme

Patterns for REST API bulk operations

l1ghtm4n.com

2 points by l1ghtm4n 13 years ago · 2 comments

Reader

ratpik 13 years ago

HTTP PATCH is a very good way to do RESTful bulk operations

I frequently use the PATCH operation to create, update and delete in bulk, sometimes a combination of these. That is the best bulk operation I have found till date that is RESTFul and compliant across client/server.

Eg.

curl --dump-header - -H "Content-Type: application/json" -X PATCH --data '{"objects": [{"body": "Surprise! Another post!.", "pub_date": "2012-02-16T00:46:38", "slug": "yet-another-post", "title": "Yet Another Post"}], "deleted_objects": ["http://localhost:8000/api/v1/entry/4/"]}' http://localhost:8000/api/v1/entry/

  • l1ghtm4nOP 13 years ago

    That is definitely another way to do it. You do lose the significance of the HTTP verb, though. One reason i've come to the dedign i proposed is that a web form usually isn't creating and deleting in a single operation, so I used that to justify different entry points.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection