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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With