PUT without data, is it RESTful?

A simple question: what if I DO NOT send data (content) via the HTTP POST / PUT method on my resource - is it still RESTful?

Obviously, the question is in which case I want to use PUT without data. Imagine a user who wants to reset his / her password (for example, this old section ).

What do you think about this? Can I send content using the POST / PUT methods? Personally, I have no problem with this, but I'm just curious what other people will say.

+7
source share
2 answers

Yes, that’s perfectly acceptable. Each action (POST for the collection, PUT for the resource) when executed without data should create a new "empty" resource. The definition of β€œempty” here will depend on what is presented.

In the specific case of resetting the user's password, however, I would not say that the above model is applied. If there really is a password resource, a PUT without data seems to suggest setting the password as empty, rather than resetting it. For this scenario, I would go with the accepted answer to this question.

+5
source

You do not need the data in POST or PUT to be useful. If you are doing something non-Idempotent (this means that the request will modify or create the resource), you do not want to use GET (is there any data to transfer or not). For example, you might have a RESTful web service that takes into account the request time and the resource URL, since all he needs to create or modify a resource is that no request data is required!

+3
source

All Articles