Reputation: 16039
I am designing a REST API for user management that must support the following CRUD operations:
/users
)/users/{userid}
)/users/{userid}
)/users/{userid}
)and operations that depend on the user status:
The payload of the above requests does not contain a user representation. It contains information such as e.g. the reson why the is blocked/suspended/archived.
According to good REST design practises URIs should not API operations, so are there other ways than e.g. POST /users/{userid}/activate
how such operations can be implemented?
Upvotes: 2
Views: 534
Reputation: 130947
According to Roy T. Fielding's dissertation, any information that can be named can be a REST resource:
5.2.1.1 Resources and Resource Identifiers
The key abstraction of information in REST is a resource. Any information that can be named can be a resource: a document or image, a temporal service (e.g. "today's weather in Los Angeles"), a collection of other resources, a non-virtual object (e.g. a person), and so on. In other words, any concept that might be the target of an author's hypertext reference must fit within the definition of a resource. A resource is a conceptual mapping to a set of entities, not the entity that corresponds to the mapping at any particular point in time. [...]
Since the status belongs to a user, the status can be managed as a sub-resource of the user resource.
To achieve it, you could have a URL like /users/{userid}/status
.
POST
or PUT
can be performed on this URL sending the relevant information to change the user status.
Upvotes: 3
Reputation: 71
Two possible options are for example:
/api/archivedUsers/
where you can POST a tuple consisting of user-URI and additional event-databoth approaches have in common, that they try to model the state of your user object (REST-like), rather than performing an action on it (what feels RPC-like). You could also check this article: REST API design resource modeling.
Upvotes: 1