What is Web API

API is an Application Programming Interface over the web which can be accessed by using HTTP protocols.

ASP.NET Web API is a framework for building web APIs, i.e., HTTP-based services on top of the ASP.NET Framework. The most common use of Web API is building RestFul Services. It supports different formats of response data. Built-in support for JSON, XML, BSON format.

ASP.NET Web API can be hosted in IIS, self-hosted, or other web server that supports .NET 4.0+. These services can be used by a broad range of clients, like:

We can use Web APIs even for the services which are not RESTful.

Representational state transfer (RESTFULL) is an architectural pattern for creating services, which uses HTTP for communication. It is an architectural pattern which specifies the set of constraints which systems must follow.

Below are the constraints,

Now, let’s discuss the difference between WCF and Web API.

WCFWEB API
We can use for creating RESTFUL Services, however, it requires a lot of configuration to achieve the same.It is specially created for REST.
WCF is more suited for the services that are transport protocol independent like HTTP, TCP, MSMQ.Web API is only suitable for Http.

Now, let’s see how to create Asp.Net Web API Project.

Now, in the above image, ValuesController is a WebAPI controller. It inherits System.Web.Http.ApiController class which is similar to ASP.NET MVC Controller, however, it handles HTTP requests.

It is created in Controller folder. All the public methods which are present in this are called as action methods.

Now, run the application and access the below URL http://localhost:XXX /api/values.

ASP..NET

Now, in the next article, we will be discussing HTTP Verbs and their implementation in Web API.