Resource in my REST API context is application code written in some programming language. CRUD operations that can be easily mapped to HTTP verbs are save/edit/delete code. Non-CRUD operations that are difficult to map to HTTP methods are deploy the code on server, execute the code, and undeploy.
Common suggestions I came across in SO are:
- Restructure the action to appear like a field of a resource, e.g. if your action is to activate an engine, design URI:
PATCH engines/123
, body:{"status":"active"}
- Treat the action like a sub-resource, e.g.
PUT engines/123/active
without a body - Use query parameters, e.g.
PUT engines/123?activate=true
- Be pragmatic and go for a non-RESTful, RPC-style URL, e.g.
PUT engines/activate?id=123
I am definitely not able to fit deploy
/undeploy
/execute
code actions to a resource as suggested in #1 and #2. Could you please share your opinion how best we can design the APIs for these actions?