Modern ASP.NET Core patterns for building RESTful APIs.
Modern ASP.NET Core patterns for building RESTful APIs.
app.MapGet(), route groups, endpoint filters.[ApiController] for automatic model validation and binding.app.Use().ProblemDetails on errors./api/v1/) or header-based versioning.TypedResults for compile-time safety.HttpClient without IHttpClientFactory: Socket exhaustion risk..Result or .Wait() in controllers.Task without async: Use async keyword or return directly.// Minimal API with route groups
var app = WebApplication.CreateBuilder(args).Build();
var users = app.MapGroup("/api/users")
.WithTags("Users")
.RequireAuthorization();
users.MapGet("/", async (IUserService service) =>
TypedResults.Ok(await service.GetAllAsync()));
users.MapGet("/{id:int}", async (int id, IUserService service) =>
await service.GetByIdAsync(id) is { } user
? TypedResults.Ok(user)
: TypedResults.NotFound());
users.MapPost("/", async (CreateUserDto dto, IUserService service) =>
{
var user = await service.CreateAsync(dto);
return TypedResults.Created($"/api/users/{user.Id}", user);
}).AddEndpointFilter<ValidationFilter<CreateUserDto>>();
// Controller with proper patterns
[ApiController]
[Route("api/[controller]")]
[Produces("application/json")]
public class OrdersController(IOrderService orderService) : ControllerBase
{
[HttpGet("{id:int}")]
[ProducesResponseType<OrderDto>(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetOrder(int id, CancellationToken ct)
{
var order = await orderService.GetByIdAsync(id, ct);
return order is null ? NotFound() : Ok(order);
}
[HttpPost]
[ProducesResponseType<OrderDto>(StatusCodes.Status201Created)]
[ProducesResponseType<ValidationProblemDetails>(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> CreateOrder(CreateOrderDto dto, CancellationToken ct)
{
var order = await orderService.CreateAsync(dto, ct);
return CreatedAtAction(nameof(GetOrder), new { id = order.Id }, order);
}
}
For middleware, exception handling, and HttpClientFactory: See references/REFERENCE.md.
security | razor-pages | blazor
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer