How web API works in asp.net
Loading
How web API works in asp.net
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naimish MakwanaRank #324 · 7.7K reputationPosted Apr 15, 2024, 12:21 AM EDT
ASP.NET Web API is a framework for building HTTP services that can be accessed from any client including browsers and mobile devices1. Here’s a high-level overview of how it works:
Application Layer: The Web API is a framework for building web services that use the HTTP protocol. The Web API returns data on request from the client, which can be in XML or JSON format2.
MVC Architecture: The MVC (Model-View-Controller) architecture is used for isolating an application to simplify testing and maintenance of the application’s code2.
Web API Architecture: The Web API uses the HTTP protocol. The selection of the action in the Web API uses the HTTP method instead of the URI path2. It uses a Routing table that defines the action to be called for which request2. The routing parameters are specified in the
webApiConfig.csfile2.Here’s an example of how the routing is configured:
config.Routes.MapHttpRoute ( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } );And here’s how you can define the code to illustrate how the routing is configured by the action:
config.Routes.MapHttpRoute ( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } );The Web API Framework matches the segments in the URI path to the template2. After the selection of the controller, the Web API selects the action by calling the
IHttpActionSelector.SelectAction2.Here’s an example of a Web API controller:
public class UsersController : ApiController { [HttpGet] public User FindUser (id) { } }You can also use other HTTP methods, such as POST, PUT, or DELETE2. If you want to override the Action Name, you can do so using the Action Name Attribute2.
Thanks