zdenda.online
zdenda.online

Reputation: 2514

PUT without data, is it RESTful?

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.

Upvotes: 8

Views: 3073

Answers (2)

cmbuckley
cmbuckley

Reputation: 42468

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.

Upvotes: 5

Ray
Ray

Reputation: 41428

You don't need data in a POST or PUT for it to be Restful. If you are doing something is non-Idempotent (meaning the request will modify or create a resource), you don't want to use GET (whether there is any data to pass or not). For example, you might have a RESTful web service that considers the time of the request and the resource url hit as all it needs to create or modify some resource--no request data needed!

Upvotes: 3

Related Questions