Getting started: Building RESTful Web API using ASP.NET Core 3.0

Sumant Mishra
3 min readDec 12, 2019

--

In this article, we will discuss how to build RESTful APIs using ASP.NET Core 3.0

Here, I will explain how to build RESTful APIs using ASP.NET Core 3.0 and Visual Studio. In my case, I am using Visual Studio with Mac. There might be some variances in the case of Visual Studio using Windows.

Table of Content

  • Prerequisites
  • Creating an ASP.NET Core Web API Project
  • What is there in the Project?
  • Run the project

Prerequisites

Before starting to build RESTful API, we need to ensure .NET Core 3.0 SDK is installed in the system or not. That can be verified by running below command in the terminal window:

dotnet -version

In my case, .NET Core SDK version is (3.0.101). If above command does not print any valid version or prints error, then download the .NET Core 3.0 SDK and install.

Creating an ASP.NET Core Web API Project

ASP.NET Core Web API project can be created by using the GUI of Visual Studio or terminal. Here, I will use Visual Studio.

Now, we are ready to create our RESTful APIs project. To start with, launch the Visual Studio IDE. It will launch the below screen:

Select New from the above wizard to get started by scaffolding a new project from a project template. This will launch the next screen:

In this wizard, select App (under .NET Core section) > API. API is a project template for creating an ASP.NET Core application with an example controller (WeatherForecastController) for a RESTful HTTP service.

Click Next. This will launch the next screen to enter the project name and location in the local drive. I have entered my project name as ProductsAPI.

Clicking on the Create button will scaffold a new project with some predefined folder structure and files like WeatherForcastController and other associated files.

What is there in the Project?

The above image shows the folder structure of the newly created project. This project contains:

  • launchSettings.json: This file contains configurations related to launching the application. But for now, two parameters need to remember such as launchUrl and applicationUrl. launchUrl contains API path (e.g. /api/products) and applicationUrl contains protocol+[subdomain]+domain+port (e.g. http://localhost:5001).
  • WeatherForecastController.cs: This class contains business logic implementation for the APIs.
  • WeatherForecast.cs: This class represents the Model for WeatherForecast.

Run the project

If we run the project using the Run button of Visual Studio, it will launch the application in the browser with a default route (launch URL), port as 5001 and URL https://localhost:5001/weatherforecast. And the response of this API will be populated in JSON format in the browser:

In one of my other article, I have discussed about Building a Simple CRUD Application using ASP.NET Core 3.0 Web API.

Hope this helps. If you found this article helpful, then please share your comments.

Thanks!

--

--

Sumant Mishra

Fullstack Architect || TOGAF 9 || AWSCSAA || Cloud Practitioner || NodeJS || React & Angular || Docker || Coder