# Your First Minimal API — .NET Core: Build, Test and Ship Web APIs

Source: https://www.geekswithgeeks.com/en/dotnet-core/api-minimal-hello

> Create a web app with one endpoint and understand the builder and app objects.

## Builder then app

`WebApplication.CreateBuilder` collects configuration and services. `builder.Build()` makes the `app`, where you map endpoints and add middleware. `app.Run()` starts the web server (Kestrel).

## Life of an HTTP request

A request passes through middleware, is matched to an endpoint, runs your handler, and the response travels back.

![Five stages from incoming request to outgoing response.](assets/figures/dotnet-core/section-4-map.svg) — Figure 4.1 — The ASP.NET Core request pipeline.

## Program.cs

Create it with `dotnet new web`. This maps one GET endpoint at `/` that returns text.

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

app.MapGet("/", () => "Hello from .NET");

app.Run();
```

## Use launchSettings for the port

During development the port comes from `Properties/launchSettings.json`. In production set it with the `ASPNETCORE_URLS` environment variable rather than hard-coding it.

**Quiz:** Which call maps a GET endpoint in a minimal API?

- [ ] app.UseGet
- [x] app.MapGet
- [ ] builder.AddGet
- [ ] app.RunGet

*Answer:* app.MapGet. `MapGet(pattern, handler)` registers a handler for GET requests on a route.
