This article explains an interesting concept of the Web API. If you are new to this concept then I am sure it will provide a little pleasure to you.
We know that the Web API is the latest technology in Microsoft's SOA platform. The beauty of the Web API is that it supports the RESTful service over HTTP, this is the latest buzzword in the industry.
We know that, one of the principals of RESTful services is, it uses a HTTP verb to map a HTTP request to an internal handler, we will see it shortly.
If you are not clear about HTTP verbs then this short paragraph is for you. HTTP is a stateless protocol and it uses verbs like GET, POST, PUT, DELETE and HEADER to perform an action on the Web Server. For example, if we make a request to a Web Server (we might want to access www.google.com) to get a web page then you are making a GET request to the web server in general and that is a normal scenario.
Now, as we have explained, the Web API is the latest service oriented platform, it also supports HTTP verbs to invoke an appropriate action depending on a HTTP request.
Let's see a practical example. We will create a Web API application and we will experiment with the GET HTTP verb.
So create a Web API project and add an API controller to the controller directory of the solution. Please ensure that you are choosing API Controller from the Template List.

We have given “person” as the controller name. Let's create it.
There is an interesting rule explaining the choice of Action() under the controller. The rule is that:
- At first it searches for Verb name within the controller. For example, if one GET HTTP request arrives at the controller then it searches for a Get() action defined in the controller. If it is present then it executes otherwise proceed to the second point.
- It searches for an action that starts with Get. For example if Get() is not present in the controller then it searches for an action that starts with GetXXXXX() for example GetData(). If there is no action that starts with even Get() then please continue to the third point.
- It searches for an attribute over action. We can set [HttpGet] or this kind of attribute over action that will help to map that specific action with a HTTP verb.
So, let's prove all the points one by one.
Invoke Action using HTTP verb
Here is our empty controller that contains the Get() method as in the following:




Join the conversation! Your thoughts help the community grow.