CURRICULUM PREVIEWRevision 1 · Open for reviewReview the full course
CONNECTING THE PIECES8 min read

Controllers and minimal APIs

Choose an endpoint shape without moving business rules into it.

The idea

A controller groups related actions; a minimal API makes a small endpoint concise. Either should translate HTTP into a use-case call and translate the result back. Keep tenant selection, validation, and error semantics explicit regardless of the routing style.

Follow the flow

Make it concrete

This excerpt isolates the concept. Connect it to the booking API as you work through the exercise.

Focused example
C#
app.MapPost("/bookings", async (
    CreateBookingRequest input, CreateBooking useCase,
    CancellationToken ct) =>
{
    var result = await useCase.ExecuteAsync(input, ct);
    return Results.Created($"/bookings/{result.Id}", result);
});

Decisions that matter

  • Thin endpoints allow the same use case to be invoked by HTTP or a background job.
  • Route constraints reject malformed route values but do not replace business validation.
  • Choose one consistent error contract and test its status, body, and content type.

Your turn

Document the response when creation succeeds, the input is invalid, or the caller lacks access to the tenant.

Reveal a worked answer

Use 201 with a resource location on success, a documented validation response for invalid input, and 401 or 403 according to authentication and authorization outcomes. Enforce tenant permission in the application boundary rather than trusting a submitted tenant ID.

Keep exploring

One more piece connected.

Mark this lesson complete when you can explain the idea.