Search code examples
resthttppostapi-designhttp-method

HTTP Method - POST vs. PATCH or PUT - When User Is Not Going to Update Anything Actually


Sometimes user is not going to send data to the server to update a resource but the resource would be updated by the server automatically. I think the best example is deactivating a profile. I describe the example below.

Example: User is trying to deactivate his profile, so he makes a call to /users/{u_id}/deactivate URI. In this example, user is not going to update anything actually, but the deactivated column would be updated by the server. What is the suitable HTTP method in this case?


Solution

  • If you are doing a "soft delete" in your system by this operation you can use HTTP DELETE for it. The url would remain as /users/{u_id} and you can respond with a Http status 204 No Content, which means that the server did the operation and there is no need to send anything in the response body.

    If this was the case of updating a single attribute of a user and the value was being provided by the calling system, PATCH would have made more sense. But since this is server marking the account as inactive; I would choose DELETE