Getting Started with Creating a New .NET Web API Project
Today, I started learning API in.NET and began by understanding how to create a new.NET Web API project.
To create a new.NET API project, it can be done via the command line or inside Visual Studio itself. When creating a new.NET API, one can either use the command line or the template creation already designed in Visual Studio.
Differences Between Command Line and Visual Studio Template
The main difference is that when you create a Web API using the command line, it doesn't come with some features such as Models, Views, and Controllers folders. Instead, it includes just a few files like:
Program.cs
appsettings.json
myWebApiName.csproj
(the main C# project file).
In this article, I will guide you on how to create a new.NET Web API using the command line.
Steps to Create a New.NET Web API Project Using Command Line
Run the command line as an administrator.
Create a folder to store the.NET project that will be created.
Locate the folder path and copy it.
In the command line, type:
cd [path you copied]
Once in the desired path, type the following command:
dotnet new webapi -n myWebApiName
Press Enter. This will create a new.NET Web API project within the folder you created earlier.
Opening the Created Project
Navigate back to the folder where the project was created.
Locate the project file named
myWebApiName.csproj
.Right-click on the file and select Open with Visual Studio.
This will open the project in Visual Studio. The structure will look like this:
|-- Program.cs
|-- appsettings.json
|-- myWebApiName.csproj
And there you have it! You’ve successfully created and opened your new.NET Web API project.
Thank You!
Thank you for reading. I hope you enjoyed this tutorial. Bye!
Attributions
I would like to thank @SundayOladiran, my tutor, for the great work done for me.