All resources are accessed via the Base url+API+ApiController combination, which is defined by default in WebApiConfig.cs. For this reason, all resources are accessed using the controller name because inside the controller there is only one method defined which has the same HTTP verb like GET or POST . We can access the web API methods using the following url structure with this default routing pattern .
Consider our REST Service URL will be http://localhost:56290/api/Home which is described as follows,
- http://localhost:56290: is the base address of web API service, It can be different as per your server.
- API: It is the used to differentiate between Web API controller and MVC controller request .
- Home: This is the Web API controller name.
To overcome the preceding mentioned issue and allow multiple GET and POST methods in a single web API controller class, you need to modify the url structure which is defined inside the WebApiConfig.cs as shown in the following image.
Now, with the preceding url pattern, we can access web API methods
From all the preceding examples and explanations, we have learned how to configure a web API routing template to use multiple GET POST methods in a single web API controller class.
I hope this article is useful for all readers. If you have any suggestions, then please mention them in the comment section.