How to Setup and run a .Net application(web API)
This is a guide to setup a .NET Core application quickly for all the beginners who want to build and Web API using .NET Core.
This is not an in-depth guide. It is made just to give you an idea of how to set it up for your projects that you will build. I am going to make a series where I will explain everything in detail about all the files used, how it actually works etc.
Let's get started
Download .NET Core and install in your local machine
Here is the link to download. Choose the .NET Core SDK and click on download
Installation
Steps to check if it installed correctly
Open CMD and type
dotnet --version
you should see an output likeC:\Users\sishub.joshi>dotnet --version 5.0.303
.NET Core SDK version is different from the one shown here, to see that follow the below step.
Type
dotnet --info
for more information
Download Visual Studio Code(here)
You can use any editor of your choice. I just prefer VSCode
Creating a .NET Core API App
- Use the command
dotnet new webapi
to create a Web API template - You can create different type of applications(console/class lib/sln). Here you can get more info about the
new
command.
Folder Structure Of the Application
For now you don't need to worry about all the files and their usage, just relax.
Let's test the application
- To Run the application use the command
dotnet run
- When the server starts, launch a browser window and type
localhost:5000/weatherforecast
- In the controller folder you will find a WeatherForecastController.cs. It is the reason for the endpoint name used above. You can change it later as it is just the boilerplate code to just test if the application is running fine.
- You will see json dummy output in your browser.
[ { "date":"2021-09-07T15:42:21.9176946+05:30", "temperatureC":1, "temperatureF":33, "summary":"Chilly" }, { "date":"2021-09-08T15:42:21.9177175+05:30", "temperatureC":43, "temperatureF":109, "summary":"Balmy" }, { "date":"2021-09-09T15:42:21.9177188+05:30", "temperatureC":53, "temperatureF":127, "summary":"Balmy" }, { "date":"2021-09-10T15:42:21.9177192+05:30", "temperatureC":-8, "temperatureF":18, "summary":"Sweltering" }, { "date":"2021-09-11T15:42:21.9177197+05:30", "temperatureC":-9, "temperatureF":16, "summary":"Freezing" } ]
- That's it, you now have a .NET web api running locally