How do you design a RESTful endpoint for an action that isn't a CRUD operation, such as canceling an order or promoting a user?
Last updated
Prefer modeling the action as a state change:
PATCH /orders/42with{"status": "cancelled"}stays fully RESTful.For a genuinely distinct operation,
POSTto an action sub-resource like/orders/42/cancelor/users/7/promote(POST because it's unsafe and often non-idempotent).Reserve verb endpoints for rare cases so the API doesn't drift into RPC, and apply one convention consistently.
- https://medium.com/@bvsahane89/custom-methods-in-rest-api-endpoints-approaches-examples-and-best-practices-284ecd23e030
- https://treblle.com/blog/rest-api-endpoint-design-guide
- https://ivankahl.com/blog/practical-guide-to-modeling-business-processes-in-rest-apis/
- https://digitalspecs.portofantwerpbruges.com/api-guidelines/
- https://dev.to/sivantha96/api-endpoint-design-crud-vs-action-specific-endpoints-a-developers-guide-1eig