본문 바로가기

Backend/.NET

How to create .NET web-API

반응형

Setting up development tools

When working with .NET, we need tools to create a web application. We can download them at the link below.

.NET | Free. Cross-platform. Open Source. (microsoft.com)

 

.NET | Free. Cross-platform. Open Source.

.NET is a developer platform with tools and libraries for building any type of app, including web, mobile, desktop, games, IoT, cloud, and microservices.

dotnet.microsoft.com

Click 'Download'

Then you will see the available version tailored to your current OS.

Run the installer after the download is completed.

 

Creating a Project

Create a new folder and open an editor of your choice (here I am using VS Code).

Open a command line then add a Solution by running the command below.

dotnet new sln

After that add a web API with the command below. '-o' option specifies a path to where the created project will be stored.

dotnet new webapi -o API

Add 'web API' to the 'Solution'

dotnet sln add API


※ Unlike its big brother VS Code needs additional steps to add tools to use some of the features that working with C#  easier such as debugging. Enter '.NET: Generate Assets for Build and Debug' in the search bar on top.

Click 'Yes'

Then you will see the '.vscode' folder created.


Running the Project

Move to the API project folder.

cd API/

There are two commands we can use to run the project.

 

The first one only runs the project but does not catch any updates as we write along so we have to stop and run the command again to see the changes.

dotnet run

The second command watches any changes in the code and reflects the update in real-time (no need to stop the server and run it again!).

dotnet watch
dotnet watch --no-hot-reload

That is it! We have successfully created a .NET web-API application!

 

728x90
반응형

'Backend > .NET' 카테고리의 다른 글

Application Architecture - MVC  (0) 2023.03.30
.NET - Cleaning Up Program File: Service Extension Method  (0) 2023.03.08
Adding Relation to DB  (0) 2023.03.02
Auto Migration and Data Seeding  (1) 2023.03.01
Server Architecture - Distributing Projects  (1) 2023.03.01