Build minimal APIs with endpoint mapping
✓Works with OpenClaudeYou are a .NET developer building REST APIs. The user wants to create a minimal API with endpoint mapping using ASP.NET Core's Minimal APIs feature (no controllers needed).
What to check first
- Run
dotnet --versionto confirm .NET 6.0 or later is installed - Verify your project file has
<TargetFramework>net6.0</TargetFramework>or higher in the.csproj
Steps
- Create a new ASP.NET Core project:
dotnet new web -n MyMinimalApi - Navigate to
Program.cs— this is where all endpoint mapping happens (no Startup.cs needed) - Call
var builder = WebApplication.CreateBuilder(args);to initialize the builder - Call
var app = builder.Build();to create the WebApplication instance - Map HTTP methods using
app.MapGet(),app.MapPost(),app.MapPut(),app.MapDelete()with route and handler function - Use inline lambda expressions or named methods as handlers; handlers receive injected dependencies and route parameters
- Call
app.Run();at the end to start the server - Run
dotnet runto test endpoints locally (default:http://localhost:5000)
Code
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services
builder.Services.AddScoped<IProductService, ProductService>();
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(b => b.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
});
var app = builder.Build();
app.UseCors();
// GET all products
app.MapGet("/api/products", GetAllProducts)
.WithName("GetProducts")
.WithOpenApi();
// GET single product by ID
app.MapGet("/api/products/{id}", GetProductById)
.WithName("GetProductById")
.WithOpenApi();
// POST new product
app.MapPost("/api/products", CreateProduct)
.WithName("CreateProduct")
.WithOpenApi();
// PUT update product
app.MapPut("/api/products/{id}", UpdateProduct)
.WithName("UpdateProduct")
.WithOpenApi();
// DELETE product
app.MapDelete("/api/products/{id}", DeleteProduct)
.WithName("DeleteProduct")
.WithOpenApi();
app.Run();
// Handler functions
async Task<IResult> GetAllProducts(IProductService service)
{
var products = await service.GetAllAsync();
return Results.Ok(products);
}
async Task<IResult> GetProductById(int id, IProductService service)
{
var product = await service.GetByIdAsync(id);
return product == null ? Results.NotFound() : Results.Ok(product);
}
async Task
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related .NET / C# Skills
Other Claude Code skills in the same category — free to download.
ASP.NET Core API
Scaffold ASP.NET Core Web API with controllers and middleware
Entity Framework Core
Set up Entity Framework Core with migrations and queries
ASP.NET Auth
Configure ASP.NET Identity with JWT and cookie authentication
Blazor
Create Blazor components for interactive web UI
.NET Testing
Write xUnit tests with Moq and FluentAssertions
SignalR
Implement real-time communication with SignalR
.NET Background Services
Create background services with IHostedService
Want a .NET / C# skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.