Skip to content
Back to skills

Endpoint Conventions

ASecurity

Minimal API endpoint conventions — static MapEndpoints classes, route groups, OpenAPI metadata, handler DI, and Result-to-HTTP conversion. Apply whenever writing or editing endpoint classes.

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 11, 2026
developmentapi

Works with

  • api

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add makigjuro/cloud-app-blueprint --skill endpoint-conventions --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Endpoint Conventions?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Endpoint Conventions
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/makigjuro-endpoint-conventions/badge)](https://www.skillsdirectory.com/skills/makigjuro-endpoint-conventions)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: endpoint-conventions
description: Minimal API endpoint conventions — static MapEndpoints classes, route groups, OpenAPI metadata, handler DI, and Result-to-HTTP conversion. Apply whenever writing or editing endpoint classes.
user-invocable: false
paths:
  - "src/**/Endpoints/**/*.cs"
  - "src/**/*Endpoints*.cs"
---

# Endpoint Rules (Minimal API)

## Structure
- Define as a static class with a `MapEndpoints(this WebApplication app)` extension method
- Group routes: `var group = app.MapGroup("/api/orders").WithTags("Orders").RequireAuthorization();`
- Handler methods are `private static async Task<IResult>` methods in the same class

## OpenAPI Metadata
- Every endpoint has `.WithName()`, `.WithSummary()`, `.WithDescription()`
- Use `.Produces<T>(StatusCodes.Status200OK)` and `.ProducesProblem(StatusCodes.Status404NotFound)` for response types
- Group with `.WithTags("DomainName")`
- Do NOT use `.WithOpenApi()` -- it is deprecated in .NET 10 (ASPDEPR002) and breaks builds with `TreatWarningsAsErrors`. The document comes from `builder.Services.AddOpenApi()` + `app.MapOpenApi()` (package `Microsoft.AspNetCore.OpenApi`); per-endpoint metadata comes from the calls above

## DI in Handlers
- Inject services via parameters with `[FromServices]` attribute
- Inject route/query params with `[FromRoute]`, `[FromQuery]`, `[FromBody]`

## Result-to-HTTP Conversion
- Convert `Result<T>` to HTTP using `.ToHttpResult()` extension method
- This maps ErrorType to status codes automatically:
  - Validation -> 400, NotFound -> 404, Conflict -> 409, Unauthorized -> 401, Forbidden -> 403, Failure -> 422, Unexpected -> 500
- POST that creates a resource: `result.ToHttpResult(created => $"/api/orders/{created.Id}")` returns 201 with a `Location` header
- Failures are RFC 7807 ProblemDetails with extensions `error` (code), `message`, `errorType` (and `errors` for validation details) -- never a custom top-level `type`, which ProblemDetails already uses

## Pattern
```csharp
public static class OrderEndpoints
{
    public static void MapEndpoints(this WebApplication app)
    {
        var group = app.MapGroup("/api/orders")
            .WithTags("Orders")
            .RequireAuthorization();

        group.MapPost("/", CreateOrder)
            .WithName("CreateOrder")
            .WithSummary("Create a new order")
            .WithDescription("Creates a pending order for the caller's tenant.")
            .Produces<CreateOrderResponse>(StatusCodes.Status201Created)
            .ProducesProblem(StatusCodes.Status400BadRequest);
    }

    private static async Task<IResult> CreateOrder(
        [FromBody] CreateOrderRequest request,
        [FromServices] CreateOrderHandler handler,
        ClaimsPrincipal user,
        CancellationToken cancellationToken)
    {
        // TenantId comes from the token claim, never from the request body
        var command = new CreateOrderCommand(user.GetTenantId(), request.CustomerName, request.TotalAmount);
        var result = await handler.Handle(command, cancellationToken);
        return result.ToHttpResult(created => $"/api/orders/{created.Id}");
    }
}
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.