English
Topic 13. Securing and operating the API: file endpoints, request limits, rate limiting, forwarded headers, health checks and maintenance
Goal: finish the HTTP API for real use: upload and download files safely with size limits, content sniffing and protective headers; throttle the sign-in endpoints against password guessing; see the client's real IP behind a proxy; answer a health check for the deployment; and clean up unsent uploads and old tokens every hour.
Where we are
Still in the web layer (Fig. 13.1). This topic is about what separates a demo from a service on the internet.
Fig. 13.1. What this topic adds
- Starting point: topic 12 — the JSON API runs and 16 API tests pass.
- At the end of the topic the API is complete except for real time, and 25 API tests pass.
Steps
- File endpoints — multipart uploads · request size limits · images by their bytes · downloads that cannot run scripts · avatar and attachment endpoints
- Rate limiting — fixed windows per IP · a 429 Problem Details response · throttling the auth group
- Operations — forwarded headers · the health check · a background cleanup · Data Protection keys · production logging
- Testing files, limits and health — test settings per class · file, rate limit and health tests
- Checkpoint — what must work, self-check questions and exercises
Materials
- Course slides, part 3, Backend in C# (slide "Rate limiting and lockout")
FileResults.cs,ImageSniffer.cs,RateLimiting.cs,MaintenanceService.csDocs/Architecture.md– running in production