christophechichmanian
christophechichmanian

Reputation: 129

Special RESTful routes

I've always been confused with RESTful routes naming conventions when it comes to very specific behaviors.

Say I have an application with a frontend app and an API and I want the administrators to be able to disable accounts (or banning them for a few days). What should be the route for it? Should I just PUT to /user/{id} with as body the following object:

{
    // Other user parameters

    "enabled": false
}

Or should I have a specific route with a verb in it such as /user/{id}/disable?

Upvotes: 0

Views: 70

Answers (1)

VoiceOfUnreason
VoiceOfUnreason

Reputation: 57327

Edits should go to the same target URI as the GET that sees the changes.

So if your administrators are using

GET /user/12345

To read the enabled field, then they should be using one of

PUT /user/12345
POST /user/12345
PATCH /user/12345

to change it.

The motivation here is caching, and in particular HTTP cache-invalidation.


I've always been confused with RESTful routes naming conventions when it comes to very specific behaviors.

The trick is to recognize that we don't use names for behaviors, we use them for resources, which we recognize as a generalization of documents. If we want to send information to a server, we do so by editing the representation of one of the documents hosted on that server.

You have to learn how to narrow HTTP into a domain application protocol.... -- Jim Webber 2011

Upvotes: 1

Related Questions