I'm trying to create a simple REST API and map it to CRUD. I have an ORM (DataMapper) which has methods like create
, update
and destroy
.
If I get it right, given a resource {a:'foo',b:'bar',c:'baz'}
, performing a PUT {b:'qux'}
is supposed to replace the resource and result in the same {b:'qux'}
, and doing a PATCH {b:'qux'}
should result in {a:'foo',b:'qux',c:'baz'}
.
Would PUT
be implemented with ORM's destroy
+create
to completely recreate a database record (with the same old id) or both PUT
and PATCH
would be mapped to update
(and only a record's fields would be manipulated)?
Well, Both the actions actually means update, where PUT is full update and PATCH is partial update. In case of PUT you already know the identifier of the resource and the resource already exists, so it is not a create and delete action per se. Infact, you can make do with providing only PUT action for your resource. The only idiosyncrasy of put is the client is supposed to provide full representation of resource. Since all request for put, must come after the GET of the resource, thus providing full representation shouldn't be problem for client anyway.