What's the RESTFul pattern for enabling and disabling a system user.
Example:
a DELETE
request to /users/123
and PATCH/UPDATE
request to /users/123
Or should I use /user/enable/123
using PUT
and /user/disable/123
using DELETE
?
A RESTful web service request contains: An Endpoint URL. An application implementing a RESTful API will define one or more URL endpoints with a domain, port, path, and/or query string — for example, https://mydomain/user/123?format=json .
REST API URL in Hub <Hub Service URL> is the Base URL of the Hub service in your network environment. For example, you have your company's server www.mycompany.com and a Hub service. You can configure Hub to be accessible by www.mycompany.com/hub or, let's say hub.mycompany.com .
First of all: DELETE
always removes a resource. So it cannot be used to change a value. Read more about the different Http methods and how they are supposed to used here: https://www.rfc-editor.org/rfc/rfc7231
You can solve this in three different ways. Whatever fits you best.
Update user object
Another approach would be by updating the User
resource.
In this case you could send a PUT /users/123
with a body that contains the full updated user object.
Partial update of user object
If you define that you are allowed to do partial updates (partial means you only need to send the changed values which will be merged in to the existing user object) you can send a PATCH /users/123
containing a json with {enabled:true}
. This is usually a bit trickier to handle on the backend.
Directly set enabled property (not recommended)
enabled
is a property of a User
. There for you can address this property directly in your URL.
You can use PUT /users/123/enabled
with a body that contains true
or false
. To this approach, also see @Roman Vottner comment below
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