managedcode/dotnet-skills/dotnet-webapi
Claude Code and agent skill by managedcode/dotnet-skills
- community
Checking that the SKILL.md file is still in the repository.
Guides creation and modification of ASP.NET Core Web API endpoints with correct HTTP semantics, OpenAPI metadata, and error handling. USE FOR: adding new API endpoints (controllers or minimal APIs), wiring up OpenAPI/Swagger, creating .http test files, setting up global error handling middleware. DO NOT USE FOR: general C# coding style, EF Core data access or query optimization (use optimizing-ef-core-queries), frontend/Blazor work, gRPC services, or SignalR hubs.
Install
npx vskill@latest install managedcode/dotnet-skills/dotnet-webapiSKILL.md
The same SKILL.md was published earlier as dotnet/skills/dotnet-webapi.
ASP.NET Core Web API
Produce well-structured ASP.NET Core Web API endpoints with proper HTTP semantics, OpenAPI documentation, and error handling.
When to Use
Use this skill when working on ASP.NET Core HTTP APIs, including:
- adding or modifying Web API endpoints implemented with controllers or minimal APIs;
- wiring up OpenAPI/Swagger metadata and endpoint documentation;
- defining request/response DTOs and consistent HTTP status code behavior;
- adding
.httpfiles or similar request-based API testing artifacts; - configuring centralized API error handling middleware or exception mapping.
When Not to Use
Do not use this skill for:
- general C# coding style or non-API refactoring;
- EF Core data modeling or query optimization work; use
optimizing-ef-core-queries; - frontend, Razor, or Blazor UI changes;
- gRPC services;
- SignalR hubs or real-time messaging flows.
Inputs / prerequisites
Before applying this skill, gather the project context needed to match the existing API style and wiring:
- the ASP.NET Core entry point, typically
Program.cs; - any existing controllers, especially classes inheriting
ControllerBaseor
using [ApiController];
- any existing minimal API registrations such as
app.MapGet,app.MapPost,
app.MapPut, or app.MapDelete;
- related DTO, model, validation, and error-handling types already used by the project;
- available build, run, and test commands so changes can be verified.
If the user asks for a new endpoint, inspect the current project structure first so the implementation follows the established conventions rather than mixing styles.
Workflow
Step 1: Determine the API style
Scan the project for existing endpoint patterns before writing any code.
- Search for classes inheriting
ControllerBaseor decorated with[ApiController]. - Search
Program.csor endpoint files forapp.MapGet,app.MapPost, etc. - If the project already uses controllers, continue with controllers.
- If the project already uses minimal APIs, continue with minimal APIs.
- If neither exists (new project), default to minimal APIs unless the user
explicitly requests controllers.
Do not mix styles in the same project.
Step 2: Define request and response types
Create dedicated types for API input and output. Never expose EF Core entities directly in request or response bodies.
Use `sealed record` for all DTOs. Records enforce immutability, provide value-based equality, and produce concise code. Seal them to prevent unintended inheritance and enable JIT devirtualization (CA1852).
Naming convention:
| Role | Convention | Example | |
|---|---|---|---|
| Input (create) | Create{Entity}Request | CreateProductRequest | |
| Input (update) | Update{Entity}Request | UpdateProductRequest | |
| Output (single) | {Entity}Response | ProductResponse | |
| Output (list) | {Entity}ListResponse | ProductListResponse |
XML doc comments on all DTOs: Add <summary> XML doc comments to every request and response type exposed in the API. These comments are automatically included in the generated OpenAPI specification, producing richer documentation without extra metadata calls.
Reference: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/openapi/openapi-comments
Date and time values — use `DateTimeOffset`: When a DTO includes a date or time property, always use DateTimeOffset instead of DateTime. DateTimeOffset preserves the UTC offset, avoids ambiguous timezone conversions, and serializes to ISO 8601 with offset information in JSON — which is what API consumers expect.
Reference: https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset JSON serialization options — preserve existing behavior by default: For existing APIs, do not introduce stricter serialization/deserialization settings unless the project already uses them or the user explicitly asks for them. Settings such as case-sensitive property matching and strict number handling can break existing clients. For new projects, or when strict JSON handling is explicitly requested, configure options like the following to minimize the potential of processing malicious requests:
Enum properties — serialize as strings by default: Unless the user explicitly requests integer serialization, all enum properties should be serialized as strings. String-serialized enums are human-readable, less fragile when values are reordered, and produce better OpenAPI documentation. See Step 4 for the JsonStringEnumConverter configuration.
Response DTOs — use positional sealed records for concise, immutable output:
Request DTOs — use sealed records with init properties so data annotations work naturally:
Follow the same pattern for Update{Entity}Request records, adding any additional properties the update requires (e.g., IsAvailable).
Minimal API validation — register explicitly: Data-annotation validation ([Required], [MaxLength], [Range], etc.) is automatic in MVC controllers, but minimal APIs require explicit opt-in. For .NET 10+ projects using minimal APIs, add the validation services in Program.cs:
This wires up an endpoint filter that validates parameters decorated with data annotations before the handler executes, returning a 400 Bad Request with a validation problem details response on failure.
Reference: https://learn.microsoft.com/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-10.0
Do not use mutable classes ({ get; set; }) for DTOs. Mutable DTOs allow accidental modification after construction and lose the self-documenting immutability that records provide.
Step 3: Implement the endpoints
Whether using controllers or minimal APIs, follow these HTTP conventions consistently.
Organizing minimal API endpoints: For projects using minimal APIs, organize endpoints by resource using static classes with a static Map<Resource> method. This pattern keeps endpoint definitions grouped by resource type, making the code more maintainable and easier to navigate as the API grows.
Pattern structure:
- Create one static class per resource (e.g.,
ProductEndpoints,CategoryEndpoints). - Define a static
Map<Resource>(this WebApplication app)extension method. - Inside the method, call
MapGet,MapPost,MapPut,MapDelete, etc. for
that resource's endpoints.
- In
Program.cs, call each resource'sMapmethod in order.
Minimal API return types — prefer `TypedResults`:
Always prefer TypedResults over the Results factory. TypedResults embeds response type information in the method signature, giving the OpenAPI generator richer metadata automatically.
When a handler returns multiple result types (e.g., Ok or NotFound), annotate the lambda with an explicit Results<T1, T2> return type. This lets you use TypedResults while still giving the compiler a common type:
Do not use TypedResults.Ok(x) and TypedResults.NotFound() in a bare ternary without an explicit return type annotation. Ok<T> and NotFound are different types with no common base the compiler can infer, which causes CS1593: Delegate 'RequestDelegate' does not take N arguments because the compiler falls back to matching RequestDelegate(HttpContext).
Fallback — `Results` factory: If a handler has many conditional branches (7+ result types), you may use the Results factory (Results.Ok(), Results.NotFound()) which returns IResult, sacrificing compile-time OpenAPI inference for simpler signatures.
Status codes:
| Operation | Success | Common errors | |
|---|---|---|---|
| GET (single) | 200 OK | 404 Not Found | |
| GET (list) | 200 OK | — | |
| POST (create) | 201 Created with Location header | 400 Bad Request, 409 Conflict | |
| PUT (full update) | 200 OK | 400 Bad Request, 404 Not Found | |
| PATCH (partial/action) | 200 OK | 400 Bad Request, 404 Not Found | |
| DELETE | 204 No Content | 404 Not Found, 409 Conflict |
POST 201 responses: Always return a Location header pointing to the newly created resource.
- Controllers: use
CreatedAtAction(nameof(GetById), new { id = ... }, response) - Minimal APIs: use
TypedResults.Created($"/api/products/{id}", response)
CancellationToken: Accept CancellationToken in every endpoint signature and forward it through to all async calls (service methods, EF Core queries, HttpClient calls). This allows the server to stop work when a client disconnects.
Step 4: Wire up OpenAPI
Every ASP.NET Core Web API should have OpenAPI documentation. Check whether the project already has OpenAPI configured before adding it.
For .NET 9+ projects, use the built-in ASP.NET Core OpenAPI support (builder.Services.AddOpenApi() + app.MapOpenApi() in development). This is all that is needed — no additional packages required.
Do NOT add any `Swashbuckle.*` NuGet package (Swashbuckle.AspNetCore, Swashbuckle.AspNetCore.SwaggerUI, Swashbuckle.AspNetCore.SwaggerGen, etc.) to .NET 9+ projects. Swashbuckle has known compatibility issues with .NET 9+ and .NET 10 OpenAPI types. For projects targeting .NET 8 or earlier, Swashbuckle is acceptable. If the project already has Swashbuckle installed, keep it unless the user asks to remove it.
Reference: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/openapi/overview
OpenAPI metadata on endpoints: Add descriptive metadata so the generated documentation is useful, not just a list of routes. For minimal APIs, chain the metadata methods:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingcatalog/Frameworks/Official-DotNet-ASPNetCore/skills/dotnet-webapi/SKILL.md
Popularity
- Repository stars
- 452
- Repository forks
- 32
- 7-day trend score
- 31
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/managedcode/dotnet-skills/dotnet-webapi)