In ASP.NET Web API, the default convention is to give the action method the same name as the HTTP verb or to name the method so that it starts with the HTTP method. In this article, we will override this default behaviour.
For e.g., in the previous article we use method name GET to handle HTTP GET. So by convention action method can be GetStudents, GetAllStudent or GetStudentById.
By the same way, the action methods of POST, PUT, and DELETE will respectively handle HTTP POST, PUT, and DELETE. To override this convention, we can use the AcceptVerbs attribute, or use HttpGet, HttpPost, HttpPut, HttpDelete, and so on.
and another version of same method:
These two method don’t follow the naming convention of Web API, but mapped through the usage of AcceptVerbs and HttpGet to the required HTTP method. In the same way, we can use custom names for action methods handling other verbs as well:
I hope that you will have better understanding of naming convention of API method. I would like to hear valuable feedback or question from you. It encourage me to write more quality article.
Happy Reading 🙂