How to design REST API for non-CRUD “commands” like activate and deactivate of a resource?

How about coming up with a noun for the feature you want to modify – ‘status’ in this instance. This would then become a sub resource of the parent entity. So for your case I would model the URI as follows:

/api/accounts/{accountId}/status

If the ‘update’ semantics are idempotent then PUT would be most appropriate, else that would need to be a POST (e.g if nonces are involved and are invalidated by the service). The actual payload would include a descriptor for the new state.

Note, I pluralized ‘accounts’ since you can have multiple of those, but status is singular since your account can have only one state.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)