English
Summary
Conclusions
A REST web service exposes resources at URIs, and actions on them are defined by HTTP methods and status codes. ASP.NET Core Minimal API describes endpoints with Map… methods, groups them with MapGroup, and binds parameters from the route, the query string, the JSON body, and the dependency container. TypedResults make response codes explicit, the built-in .NET 10 validation checks DTOs, and ProblemDetails defines a single error format; OpenAPI and .http files are used to test the service. A repository behind an interface makes it possible to move from in-memory data to EF Core without changing the endpoints. Clients use an HttpClient from IHttpClientFactory and handle server unavailability and ProblemDetails bodies.
Self-check questions
- What parts do an HTTP request and response consist of? What are the
Content-TypeandLocationheaders for? - Which HTTP methods are safe, and which are idempotent? Why does this matter when retrying a request?
- What status codes does a service return after a successful
GET,POST,PUT,DELETE? - What are a resource and a representation in REST? How do you build URIs for collections and items correctly?
- What does
JsonSerializerOptions.Webenable? How do you write enumerations as names? - How does Minimal API differ from controllers? What stages does
Program.csconsist of? - What is the middleware pipeline? Why does the order of
app.Use…calls matter? - How do you define a route parameter with a constraint? What is
MapGroupfor? - From which sources does ASP.NET Core take the values of handler parameters?
- How does
TypedResultsdiffer fromResults? What is theResults<Ok<T>, NotFound>type for? - How do you enable the built-in validation in .NET 10? What does the client receive on an error?
- What is
ProblemDetails? Which calls are needed so that all errors have this format? - How do you get a service's OpenAPI document? How do you send a request from an
.httpfile? - Why is
DbContextregistered as Scoped? How do you implement pagination in the database? - Why must you not create an
HttpClientfor every request? What is a typed client?
Useful links
- Minimal API: https://learn.microsoft.com/aspnet/core/fundamentals/minimal-apis
- Parameter binding: https://learn.microsoft.com/aspnet/core/fundamentals/minimal-apis/parameter-binding
- Handling errors in APIs: https://learn.microsoft.com/aspnet/core/fundamentals/error-handling-api
- What's new in ASP.NET Core 10 (validation): https://learn.microsoft.com/aspnet/core/release-notes/aspnetcore-10.0
- OpenAPI in ASP.NET Core: https://learn.microsoft.com/aspnet/core/fundamentals/openapi/overview
.httpfiles in Visual Studio: https://learn.microsoft.com/aspnet/core/test/http-filesSystem.Text.Json: https://learn.microsoft.com/dotnet/standard/serialization/system-text-json/overviewHttpClient: https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclientIHttpClientFactory: https://learn.microsoft.com/dotnet/core/extensions/httpclient-factory- HTTP Semantics, RFC 9110: https://www.rfc-editor.org/rfc/rfc9110