Reputation: 1752
Designing an API as RESTful as possible, I wonder if it is ok to divide a resource with specific sub-URIs.
Let's have the following URIs:
GET /users
: list usersGET /users/42
: get detailed information about user with id=42
, e.g.:
{
id: 42,
first_name: "Done",
last_name: "Joe",
is_active: false
}
I am about to consider the "is active" status as its own resource:
GET /users/42/is_active
: get activity status about user with id=42
{
is_active: false
}
PUT /users/42/is_active
: set activity status about user with id=42
using as body:
{
is_active: false
}
Any pro's or con's for doing so?
Upvotes: 1
Views: 131
Reputation: 13682
What you're talking about is called a "micro-resource". It's useful for doing partial updates in an idempotent manner. It's not popular in more well-known APIs, but it's certainly a valid design approach.
Upvotes: 1