USE strict ordering for controller actions
When building a RESTful API controller, it is important to follow a consistent and logical order for HTTP verbs. The most common order is to group the HTTP verbs in the following order: GET, POST, PUT, PATCH, and DELETE.
The GET verb is typically used to retrieve data from the API, while POST is used to create new resources in the API. PUT and PATCH are used to update existing resources, with PUT replacing the entire resource and PATCH updating specific fields. Finally, DELETE is used to remove resources from the API.
At BtcTurk we intent to keep all these HTTP verbs organized throughout all projects and defined a strict ordering for this requirement.
- [HttpGet("")] Start with Query endpoint
- [HttpPost("")] Implement Create endpoint
- [HttpGet("{id}")] Implement Get endpoint
- [HttpPut("{id}")] Implement Put endpoint
- [HttpPatch("{id}")] Implement Patch endpoint
- [HttpDelete("{id}")] Implement Delete endpoint
- Follow this order for subsequent path segments
By following this order, developers can create controllers that are easy to read and understand, with each HTTP verb performing a specific action that is consistent with RESTful API best practices. In addition, this order helps to ensure that the API is well-structured and maintainable over time, as new endpoints can be added and updated without disrupting the overall organization of the controller.
Overall, while there is no strict requirement for HTTP verb ordering in a RESTful API controller, following a consistent and logical order can help to improve the clarity and maintainability of the API. By adhering to best practices for HTTP verb ordering, developers can create APIs that are easier to use and understand for clients, and easier to maintain and update over time.