Reputation: 5875
I want to do something more REST
like this:
Select resources whose field1
equals foo
, and update field1
to bar
UPDATE XXX SET field1 = "bar" WHERE field1="foo"
Two solutions as I can see:
GET
items matching my requirement, then PUT
to update them. Maybe with Etag
or If-Match
to guarantee it's atomic.PUT
method handler, so the query string represent the WHERE clause in the SQL and the content of the PUT
request represent the SET
clause in SQLPersonally I prefer the latter solution, but in REST
, the PUT
method is supposed to overwrite a resource, not many resources at a time, nor just updating some fields of the resource.
I also checked the HTTP PATCH
method proposal. It makes "updating some fields of a resource" possible, but it's not used to update many resources at once too.
So what's your solution? I'd like to see your best practice :-)
Upvotes: 2
Views: 105
Reputation: 10145
Random untested ideas:
url: PUT /xxx/*/field1/foo
body: "bar"
or (if you can predict/bound the key range for XXX):
PUT /xxx/0,9999999/field1/foo
"bar"
or if you are okay with 2 calls, maybe:
GET /xxx?field1="foo"
POST /xxx/id1,id2,...,idn/field1
"bar"
Upvotes: 1