Create And Consume ASP.NET Core Web API
Contents
Hello to everyone! In this article, I will show you how to develop and test web services using ASP.NET Core. At the end of this post you will learn how to create a web API project and test it in the browser.
First of all, let’s briefly talk about what is ASP.NET Core.
What is ASP.NET Core?
ASP.NET Core makes it easier for developers working on software development with .NET technologies to develop more responsive, reliable and extensible applications.
ASP.NET Core has redesigned the entire ASP.NET infrastructure and combined it with Web API and MVC infrastructures.
Thanks to ASP.NET Core technology, it is possible to create modern applications with less effort and cost in a shorter time.
Prerequisites
- Visual Studio 2019 16.4 or later with the ASP.NET and web development workload
- .NET Core 3.1 SDK or later
Create an ASP.NET Core Web API Project
After starting Visual Studio, click on Create a new project title on the screen that appears.
Next, type Create an ASP.NET Core Web Application in the search bar and select the first option that appears and click Next. Make sure the selected language is C#.
Then select the Project Name, Location and Solution Name and click the create button.
Then select the API option in the window that opens. In addition, I removed the Configure for HTTPS option in order to avoid problems while testing this project with different tools.
And our project is ready. The project comes ready as an example of the WeatherForecast.cs Model class and the WeatherForecastController.cs class inside the Controllers folder.
Test the API
Let’s run and test it with the ready-made classes without any additions to the project. Run the project by pressing Ctrl + F5. Visual Studio will start a browser and run the project on localhost with a randomly selected port number.
Visual studio went to https://localhost:<port>/weatherforecast and worked successfully.
Conclusion
In this post I showed you how to create and run an ASP.NET Core Web API project. Then we examine the ASP.NET Core project structure and files. Stay blowing.
One Comment