Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP MODIFY verb for REST?

As far as I see, there's no RESTful way to apply a modification to a resource. In order to do it, you have to PUT the resource as a whole, overwriting the previous representation. I think this is source of problems, in particular when the resource has a large representation.

I believe this hints at the lack of a verb in HTTP1.1 : something like MODIFY, or PATCH. Not even WebDAV has this verb (it has PROPPATCH, whose concept is similar, but not for the resources).

Isn't the current HTTP 1.1 set of verbs too limited for real world RESTing ?

Edit: I found a proposal at IETF about the PATCH verb

https://datatracker.ietf.org/doc/html/draft-dusseault-http-patch-15

This specification defines the new HTTP/1.1 [RFC2616] method PATCH that is used to apply partial modifications to a resource.

A new method is necessary to improve interoperability and prevent errors. The PUT method is already defined to overwrite a resource with a complete new body, and can not be reused to do partial changes. Otherwise, proxies and caches and even clients and servers may get confused as to the result of the operation. PATCH was mentioned in earlier HTTP specifications, but not completely defined.

As far as I see, the only problem of such a verb is lack of idempotency.

Edit: As of March 2010, RFC 5789 exists (PATCH Method for HTTP).

like image 422
Stefano Borini Avatar asked Nov 04 '09 06:11

Stefano Borini


People also ask

What are the different HTTP verbs used in rest?

The primary or most-commonly-used HTTP verbs (or methods, as they are properly called) are POST, GET, PUT, PATCH, and DELETE. These correspond to create, read, update, and delete (or CRUD) operations, respectively.

Which of these are the 4 correct types of REST requests?

The most common are: GET, POST, PUT, and DELETE, but there are several others. There is no limit to the number of methods that can be defined and this allows for future methods to be specified without breaking existing infrastructure.


2 Answers

You could partition the resource into individually updatable sub-resources.

E.g. you have a /user resource representing user account information you could create a /user/email sub-resource, then do a PUT on it to update just the email.

like image 71
DSO Avatar answered Sep 23 '22 02:09

DSO


You can use POST for partial updates. It's not ideal, but it's fairly RESTful.

like image 28
Avi Flax Avatar answered Sep 25 '22 02:09

Avi Flax