What is the best practice to write custom RESTful API endpoints?
Suppose we have an entity named Comments
. And there's regular CRUD for interacting with API requests through below URLs:
- GET : /:postId/comments
- POST /:postId/comments
- GET /:postId/comments/:commentId
- PUT /:postId/comments/:commentId
- DELETE /:postId/comments/:commentId
My problem begins when we need to add a new endpoint to either reject or accept by some administrator working with the application.
Here are some available scenarios to achieve this functionality:
- Define a new route with a
PUT
method and/moderate
URL - Define two new routes with
PUT
methods and/accept
or/reject
URL - Define a whole new resource to moderate the comments
- Send some extra info through the existing
/:postId/comments/:commentId
URL to tell the controller we're moderating
What's the best practice to develop this kind of endpoints?