Building Your First Web API with ASP.NET Core Part 1: Getting Started with REST

Published: (March 9, 2026 at 08:38 PM EDT)
4 min read
Source: Dev.to

Source: Dev.to

What is REST?

REST (Representational State Transfer) is an architectural pattern for designing networked services. It uses standard HTTP verbs—the same ones your browser uses every day—to perform operations on resources.

HTTP VerbWhat It Does
GETFetch data
POSTCreate something new
PUTReplace/update existing data
PATCHPartially modify existing data
DELETERemove data

A RESTful API is defined by three things:

  1. A base URI (e.g., https://api.example.com)
  2. The HTTP methods above
  3. A data format—usually JSON, sometimes XML

Routing ties everything together. For example, requests to /pizza might go to a PizzaController, while /order routes to an OrderController. Each resource gets its own logical home in your code.

Why ASP.NET Core?

  • JSON out of the box – ASP.NET Core automatically serializes C# classes to JSON.
  • Built‑in security – HTTPS is enabled by default, with native support for JWT authentication and policy‑driven authorization.
  • Attribute‑based routing – Define routes directly on controller methods using attributes, keeping routing logic co‑located with the code.
  • Code reuse across .NET – The same models and business logic can be shared with mobile, desktop, or other .NET services.

Prerequisites

  • Basic familiarity with C# (beginner level is fine)
  • .NET 8 SDK installed locally
  • Visual Studio Code
  • C# Dev Kit extension for VS Code
  • REST Client extension for VS Code

To confirm your .NET version, run:

dotnet --list-sdks

You should see something like 8.0.100. If not, download the latest .NET 8 SDK from the official Microsoft site.

Creating the Project

  1. Open VS Code → File > Open Folder and create a new folder called ContosoPizza.
  2. Open the integrated terminal (View > Terminal) and run:
dotnet new webapi -controllers -f net8.0

This scaffolds a new ASP.NET Core Web API project with controller support. The generated structure looks like:

├── Controllers/
├── obj/
├── Properties/
├── appsettings.Development.json
├── appsettings.json
├── ContosoPizza.csproj
├── ContosoPizza.http
├── Program.cs
└── WeatherForecast.cs

Key items

  • Controllers/ – Where your API endpoint logic lives
  • Program.cs – App startup configuration and HTTP pipeline
  • ContosoPizza.http – A handy file for testing your API inside VS Code
  • ContosoPizza.csproj – Project metadata and dependencies

VS Code may prompt you to add debugging assets—click Yes.

Running the API

Start the development server:

dotnet run

You’ll see output similar to:

Now listening on: https://localhost:7294
Now listening on: http://localhost:5118
Application started. Press Ctrl+C to shut down.

Note the HTTPS port (e.g., 7294). Open a browser and navigate to:

https://localhost:{PORT}/weatherforecast

You should receive a JSON response with randomized weather data, confirming that the scaffolded endpoint works.

Testing with the REST Client Extension

The project includes ContosoPizza.http, which works with the REST Client extension. Open the file; it already contains a GET request for /weatherforecast.

Click Send Request above the GET line. The response panel will show something like:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
...

[
  {
    "date": "2024-01-18",
    "temperatureC": -2,
    "temperatureF": 29,
    "summary": "Warm"
  },
  ...
]

This workflow lets you test endpoints without leaving VS Code.

Testing with HTTP REPL

ASP.NET Core also provides an interactive tool called HTTP REPL.

Install it globally:

dotnet tool install -g Microsoft.dotnet-httprepl

Connect to your running API:

httprepl https://localhost:{PORT}

Inside the REPL you can explore the API like a file system:

ls                    # List available endpoints
cd WeatherForecast    # Navigate to an endpoint
get                   # Issue a GET request
exit                  # Quit the REPL

What’s Next?

The current project only contains the sample weather‑forecast endpoint. In Part 2 we will:

  • Dive into how ASP.NET Core controllers work
  • Break down the WeatherForecastController code
  • Create a Pizza model and an in‑memory data service
  • Wire up a custom PizzaController

By the end of Part 2 you’ll be able to fetch pizza data through your own API endpoint.


Tags: dotnet csharp webapi aspnetcore beginners

0 views
Back to Blog

Related posts

Read more »