Web API : Configuration over Convention

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.

For Example:

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:

A hope

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 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s