0

I want to design my REST endpoint for enabling or disabling a user

My thought is to use PUT without body, with this URLs:

  1. PUT /.../users/{userName}/enable
  2. PUT /.../users/{userName}/disable

Is it possible to use PUT without a body? Do you have any other suggestions?

  • Does this answer your question? [Is an HTTP PUT request required to include a body?](https://stackoverflow.com/questions/1233372/is-an-http-put-request-required-to-include-a-body) – Joachim Sauer Feb 08 '23 at 13:36

2 Answers2

0

Short answer: No.

Personally, I have also used empty PUT requests when merely updating a resource using an idempotent action - like toggling enable/disable.

Possible duplicate of: Is an HTTP PUT request required to include a body?

morsor
  • 1,263
  • 14
  • 29
0

Is body required in PUT request?

No - a PUT request with an empty body is how we would tell a web server that we want the representation of a resource to be zero bytes long.

PUT /example HTTP/1.0
Content-Type: text/plain
Content-Length: 0


I want to design my REST endpoint for enabling or disabling a user

A bit of prior art that you might consider is the github starring API, which uses PUT with an empty body to turn on a star, and DELETE to turn off a star.

Note that both requests use the same URI - that's appropriate because we want general purpose cache invalidation to "just work".


It may be helpful to be clear in your mind the differences between the semantics of the message ("please save this empty document on the web server") and the business side effects ("enable the user"). See Webber 2011.

VoiceOfUnreason
  • 52,766
  • 5
  • 49
  • 91