ASP.NET Core Web API & REST
HTTP methods
| Method | Safe | Idempotent | Typical response |
|---|---|---|---|
| GET | ✓ | ✓ | 200 |
| POST | ✗ | ✗ | 201 + Location |
| PUT | ✗ | ✓ | 200/204 |
| PATCH | ✗ | ✗ | 200/204 |
| DELETE | ✗ | ✓ | 204 |
Status codes to remember
200 · 201 · 202 · 204 · 304 · 400 · 401 (who are you?) · 403 (not allowed) · 404 · 409 · 412 · 415 · 422 · 429 · 500 · 502 · 503 · 504.
Pipeline order
app.UseExceptionHandler();
app.UseHttpsRedirection();
app.UseCors("spa");
app.UseAuthentication();
app.UseAuthorization();
app.UseRateLimiter();
app.UseOutputCache();
app.MapControllers();Minimal API essentials
MapGet/MapPost/MapPut/MapPatch/MapDelete · MapGroup · TypedResults · Results<Ok<T>, NotFound> · [AsParameters] · AddEndpointFilter · RequireAuthorization · RequireRateLimiting · WithTags/WithName.
Security
JWT = header.payload.signature (signed, not encrypted) · validate iss/aud/exp/signature · Auth Code + PKCE / Client Credentials · CORS ≠ auth · rate limit · HTTPS/HSTS · Key Vault.
Caching options
HTTP headers/ETag · Output cache · IMemoryCache · IDistributedCache (Redis) · HybridCache (.NET 9).
Remember
DTOs not entities · ProblemDetails for errors · CancellationToken everywhere · IHttpClientFactory · pagination with max size · version before breaking · idempotency keys for payments.