Menu
CoddyTech

Your First Endpoint

Part of the Minimal APIs section of Coddy's ASP.NET Core journey. Lesson 1 of 20.

A web API is a program that waits for requests and sends back responses. A request names a method, such as GET, and a path, such as /weather. ASP.NET Core is the part of .NET that builds web apps, and a minimal API is its shortest form: Program.cs creates the app, maps paths to code, and runs it.

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/weather", () => "Sunny, 24 degrees");

app.Run();

MapGet means: when a GET request for /weather arrives, run this lambda and send back what it returns. A string goes back as text with status 200, which means OK. On your computer dotnet run starts the app on a port. Here Run starts it, and the request bar beside your code sends it requests.

challenge icon

Challenge

Beginner

In this section you build a recipe API. It starts with a home endpoint that says the API is up.

  1. In Program.cs, between builder.Build() and app.Run(), map GET / with app.MapGet.
  2. Its lambda returns the text Recipe API is running, exactly as written here.

Try it: press Run, then send GET /. It responds with status 200 and Recipe API is running. Send GET /recipes too: nothing is mapped there yet, so it responds with 404.

Try it yourself

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.Run();
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Minimal APIs