So traditional API resources allow you to GET
, PUT
, PATCH
, DELETE
etc a resource.
/api/v1/user/$id
However what is the technical term for a route that performs an action and returns some response about the outcome of that action?
/api/v1/flushcache
One way is to just have a cache
resource:
/api/v1/cache
Which would return some cache state for example application/vnd.company.cachestate+json
:
{
"state": "active",
"objectCount": 123
}
Then you could PUT
the same representation:
{
"state": "flushed"
}
Which could return:
{
"state": "active",
"objectCount": 0
}
The point is, you have to first formulate the problem in the existing terminology. The terms used are always:
So, again, there is usually no Resource that "does" something, more like, Resources represent some Business Entity, and the standard operations (GET, PUT, POST, DELETE, etc.) are mapped to some operations on that entity.