Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PUT without data, is it RESTful?

Tags:

rest

http

Simple question: what if I'm NOT sending data (content) via HTTP POST/PUT method on my resource — is it still RESTful?

Obviously, the question is in which case would I want use PUT without data. Imagine a user that wants to reset his/her password (like in this older topic).

What do you think of it? Is it okay NOT to send content with POST/PUT methods? Personally I have no problem with it but I'm just curious what would other people say.

like image 998
zdenda.online Avatar asked Oct 17 '12 21:10

zdenda.online


People also ask

Can we use Put instead of POST in REST?

Another important difference between the methods is that PUT is an idempotent method, while POST isn't. For instance, calling the PUT method multiple times will either create or update the same resource. In contrast, multiple POST requests will lead to the creation of the same resource multiple times.

Is RESTful always JSON?

REST is designed to be simple. The gist of it is that each url corresponds to a unique resource. The format of the resource is commonly json, but can be anything, and is typically determined by the "extension" or "format" part of the url.

What is put method in REST?

The PUT method requests that the enclosed entity be stored under the supplied URI. If the URI refers to an already existing resource, it is modified and if the URI does not point to an existing resource, then the server can create the resource with that URI.

What is the difference between put and PATCH in REST API?

PUT means replace the entire resource with given data (so null out fields if they are not provided in therequest), while PATCH means replace only specified fields. For the Table API, however, PUT and PATCH mean the same thing.


1 Answers

Yes, this is perfectly acceptable. Each action (POST to a collection, PUT to a resource) when performed with no data should create a new, "empty" resource. The definition of "empty" here would depend on what is being represented.

In the specific case of resetting a user's password, however, I wouldn't say that the above model applies. If there truly is a password resource, a PUT with no data would seem to suggest setting the password to be empty, rather than resetting it. For this scenario, I'd go with the accepted answer from that question.

like image 121
cmbuckley Avatar answered Nov 14 '22 07:11

cmbuckley