In this tutorial, you will learn about ASP.Net Web API (Application Programming Interface) and how to create Web API in ASP.NET C#. We can build Web API using different technologies such as Java, .NET, etc. Keep reading on How to create a WCF REST Service C#, Wikipedia Search API JavaScript Example.
- You may be interested in ASP.NET Core 3.1 Web API Quick Starter Kit
What is Web API in ASP.NET?
ASP.NET Web API is a framework for building HTTP-based services that can be consumed from any client including browsers and mobile devices. It is an ideal platform for building RESTful applications on the .NET Framework.
ASP.NET Web API Characteristics
- It is based on RESTful architecture.
- Uses standard HTTP methods (GET, PUT, POST, DELETE).
- It supports multiple text formats like XML, JSON, etc.
- Completely stateless.
- It supports ASP.NET MVC features.
- Supports Self Hosting and IIS Hosting.
How to create Web API in ASP.NET
You can create a Web API project in two different ways.
- Stand-alone Web API Project.
- Web API with MVC Project.
In this article, I will explain how to create web API in asp.net c# empty project step-by-step. Let’s get started with a new stand-alone web API project:-
Step 1: Open Visual Studio 2019 and click on the Create a new project option.
This will open the New Project popup as below:-

Step 2: Select the web template in the left panel and check the Web API checkbox and uncheck the Configure for Https from the right panel. Enter the name of the project, location, and solution name as shown above. Clicking on OK will open a popup as shown below.

In the above popup, select Empty as a template and click ok. This will create an empty “WebAPIStart” project.

Now, let’s add Web API Controller by right-clicking on the Controllers folder -> select Controller.. this will open popup as below.

Select Controller in the left panel and Web API 2 Controller – Empty in the middle panel and click Add. This will open another popup to enter the name of your controller as below. Enter the controller name and click Add.

Now, we need to add action methods. Here, we will add some action methods as shown below.
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; using WebAPIStart.Models; namespace WebAPIStart.Controllers { public class UserController : ApiController { List<User> userList = new List<User>(); public UserController() { userList.Add(new User { UserId = 1, Name = "Ravi", Address = "Noida" }); userList.Add(new User { UserId = 2, Name = "Sachin", Address = "Agra" }); } //api/user public IHttpActionResult GetUsers() { return Ok(userList); } //api/user/1 public IHttpActionResult GetUser(int id) { User user = userList.Find(u => u.UserId == id); return Ok(user); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace WebAPIStart.Models { public class User { public int UserId { get; set; } public string Name { get; set; } public string Address { get; set; } } }
Now, compile and run the project and navigate to http://localhost:16053/api/user in the browser. It will display the following result.

Conclusion
I hope you liked this tutorial on how to create web api in asp.net c#. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.
Very simple but clear and effective.
Thanks, Giulio.
You can also look into our next article where I have explained how to implement asp.net web api CRUD operations. | https://dotnettec.com/web-api-crud-operations-using-asp-net-mvc-and-entity-framework/