ASP.NET Web API with C# - Create first Project
Hello..!!
We went through lot of theory till now. So let's jump into bit coding by creating our first ASP.NET Web API using C#
Contents in this article
Requirements
There are some requirements to create Web API
Create Web API project
I am using Visual Studio Community Edition 2019 in this article as I am not that rich to use licensed versions of VS✌✌. If you are using another VS Edition, you may have some professional and rich look but navigation will be similar almost
Let's open Visual Studio, in the home screen it will show up some existing projects. Click on Create a New Project
or go through Visual Studio -> File -> New -> Project/Solution
Then you will be shown with a screen where you need to select the type of project we are going to work on. Select "ASP.NET Web Application" and click Next. Make sure to select .NET Framework with C#. There will be other options like Core/.NET Core with VB/F#
Now, we need to give a name to the project. In our case we are going to work on famous Student list(id,name,class). So give it as SchoolManagement.API.. Oh My God..!! still boring student data..??
We are grown up, need to think big.. Okay, assume that we are going to work on below project
"Build a Web API project for a Super Market/ Mart where there is a huge DB warehouse of Products which are belongs to different categories and with prices. These products are associated with Sellers data. This DB warehouse also contains all Orders data associated with Customer details"
Customer/Seller/Admin/Guest User any of these can send a request to our API to get the required information based on their choice. For this we will charge the company owner monthly and will be RICH and will buy an Island to enjoy...
So, Let's name it smartly as "isMart.API" which is a smart enough Web API that provides complete MART information
Now, there will be another screen which shows option as Empty. If you select this it will create an empty project template so that you can build any type of Web Application. But,we need to add folder structure to it and work with that from scratch.
Along with this there are options for different flavors of ASP.NET Web Applications(Web Forms, MVC, Web API, Single Page Application). With these options VS will create required project template to work with predefined scaffolding (folders structure with basic CRUD operations).
So that we can easily connect with the structure and code samples and build our application with less efforts to understand the flow
Here, we need to select Web API option and click Next. Sit back, have a cup of coffee/tea and Relax for some time. So that VS will create Web API folder structure with sample code
You will get below screen
As you can observe, VS has created some folder structure and code inside it for us. Let's Thank VS for making our job bit easier
Okay, will test our project now whether it is running properly or not by running the application in debug mode. Click ➤ IIS Express Browse/Start or Right click on the Project(Not solution) -> Debug -> Start new instance
Wait for some time.. Below screen will be displayed in browser. As you can see the URL "https://localhost:44355/" this is a local application which is running on local IIS Express server. In your case port number after localhost will vary
Basic Get Operation
If you expand Controllers folder, will find ValuesController.cs. Double click to see the code. As you can see there are some predefined methods which were given as part of the default Web API template
Let's test those. Run the project in debug mode as earlier
Browse "https://localhost:44355/api/values/" and "https://localhost:44355/api/values/1"
You will see below values in the browser respectively
URL format: https://domain.com/api/controller/action?id=123
If we observe the URL, there is api which denotes it is an API and values is controller. As we didn't pass the action method in the URL, it is automatically hitting the default GET method in that API controller

Yayyy.. !! We did it. This is the first step stone to become RICH with our application
Download Web API solution
If you are having any trouble, leave a comment below..
We will continue creating our Project in further articles. Stay tuned
Thanks.. !!!
We went through lot of theory till now. So let's jump into bit coding by creating our first ASP.NET Web API using C#
Contents in this article
- Requirements
- Create Web API project
- Basic Get operations
Requirements
There are some requirements to create Web API
- Visual Studio 2010 or latest
- .NET Framework 4.0 or more
Bit patience as well
Create Web API project
I am using Visual Studio Community Edition 2019 in this article as I am not that rich to use licensed versions of VS✌✌. If you are using another VS Edition, you may have some professional and rich look but navigation will be similar almost
Let's open Visual Studio, in the home screen it will show up some existing projects. Click on Create a New Project
or go through Visual Studio -> File -> New -> Project/Solution
Then you will be shown with a screen where you need to select the type of project we are going to work on. Select "ASP.NET Web Application" and click Next. Make sure to select .NET Framework with C#. There will be other options like Core/.NET Core with VB/F#
Now, we need to give a name to the project. In our case we are going to work on famous Student list(id,name,class). So give it as SchoolManagement.API.. Oh My God..!! still boring student data..??
We are grown up, need to think big.. Okay, assume that we are going to work on below project
"Build a Web API project for a Super Market/ Mart where there is a huge DB warehouse of Products which are belongs to different categories and with prices. These products are associated with Sellers data. This DB warehouse also contains all Orders data associated with Customer details"
Customer/Seller/Admin/Guest User any of these can send a request to our API to get the required information based on their choice. For this we will charge the company owner monthly and will be RICH and will buy an Island to enjoy...
So, Let's name it smartly as "isMart.API" which is a smart enough Web API that provides complete MART information
Now, there will be another screen which shows option as Empty. If you select this it will create an empty project template so that you can build any type of Web Application. But,we need to add folder structure to it and work with that from scratch.
Along with this there are options for different flavors of ASP.NET Web Applications(Web Forms, MVC, Web API, Single Page Application). With these options VS will create required project template to work with predefined scaffolding (folders structure with basic CRUD operations).
So that we can easily connect with the structure and code samples and build our application with less efforts to understand the flow
Here, we need to select Web API option and click Next. Sit back, have a cup of coffee/tea and Relax for some time. So that VS will create Web API folder structure with sample code
You will get below screen
As you can observe, VS has created some folder structure and code inside it for us. Let's Thank VS for making our job bit easier
Okay, will test our project now whether it is running properly or not by running the application in debug mode. Click ➤ IIS Express Browse/Start or Right click on the Project(Not solution) -> Debug -> Start new instance
Wait for some time.. Below screen will be displayed in browser. As you can see the URL "https://localhost:44355/" this is a local application which is running on local IIS Express server. In your case port number after localhost will vary
Basic Get Operation
If you expand Controllers folder, will find ValuesController.cs. Double click to see the code. As you can see there are some predefined methods which were given as part of the default Web API template
Let's test those. Run the project in debug mode as earlier
Browse "https://localhost:44355/api/values/" and "https://localhost:44355/api/values/1"
You will see below values in the browser respectively
URL format: https://domain.com/api/controller/action?id=123
If we observe the URL, there is api which denotes it is an API and values is controller. As we didn't pass the action method in the URL, it is automatically hitting the default GET method in that API controller
Yayyy.. !! We did it. This is the first step stone to become RICH with our application
Download Web API solution
If you are having any trouble, leave a comment below..
We will continue creating our Project in further articles. Stay tuned
Thanks.. !!!
Jokes In middle super bro
ReplyDelete