ASP.NET Core Web API

Build the kind of APIs product companies run in production. Start with how HTTP really works and every status code from 100 to 511, then build a .NET Web API with minimal APIs and controllers, validation and ProblemDetails errors, EF Core, JWT authentication, OpenAPI docs, versioning, caching, rate limiting, resilience, tests and monitoring.

10 chapters63 status codes80 practice questions
Open the courseChapters, a study plan and timed practice exams.

Chapters

  1. 1. How HTTP and REST work 25 min

    What travels over the wire when a client calls an API: methods, URLs, headers and bodies, which methods are safe and idempotent, and how to design clean REST resources.

    • Read a raw HTTP request and response.
    • Know which methods are safe and which are idempotent.
    • Design resource URLs and pick the right method for each action.
    • Use the common request and response headers correctly.
  2. 2. Status codes, part 1: 1xx, 2xx and 3xx 25 min

    Every informational, success and redirection status code with what it means and when an API should use it, plus the codes you should never send.

    • Know the five classes of status codes and what each one signals.
    • Pick between 200, 201, 202 and 204 for API responses.
    • Tell 301, 302, 303, 307 and 308 apart.
    • Use 304 Not Modified with ETags to save bandwidth.
  3. 3. Status codes, part 2: 4xx and 5xx 30 min

    Every client error and server error code, the pairs people mix up (401 vs 403, 400 vs 422, 404 vs 410, 502 vs 503 vs 504) and a quick guide to pick the right one.

    • Know all 4xx and 5xx codes and what each means.
    • Choose correctly between 400, 401, 403, 404, 409, 412, 422 and 429.
    • Tell 500, 502, 503 and 504 apart when debugging.
    • Return errors that never leak internal details.
  4. 4. Build your first API: minimal APIs and controllers 30 min

    Create a .NET Web API, compare minimal APIs with controllers, route and bind parameters, and return typed results with the right status codes.

    • Create a Web API project and read Program.cs.
    • Choose between minimal APIs and controllers.
    • Use route constraints and parameter binding.
    • Return TypedResults so the status codes appear in OpenAPI.
  5. 5. Validation and consistent errors with ProblemDetails 30 min

    Validate input with data annotations, turn validation failures and exceptions into RFC 9457 ProblemDetails responses, and keep error bodies safe.

    • Validate request bodies in minimal APIs and controllers.
    • Return validation errors as ValidationProblemDetails.
    • Handle unexpected exceptions globally with IExceptionHandler.
    • Avoid leaking stack traces and internal details.
  6. 6. Data with EF Core: DTOs, paging and concurrency 30 min

    Connect an API to a database with EF Core, keep entities out of responses with DTOs, page large lists, apply PATCH safely and stop lost updates with ETags.

    • Use DbContext with async queries in endpoints.
    • Map entities to DTOs instead of returning entities.
    • Choose offset or keyset pagination.
    • Prevent lost updates with concurrency tokens and 412.
  7. 7. Authentication, authorization and API security 35 min

    Protect endpoints with JWT bearer tokens from Microsoft Entra ID or another identity provider, write authorization policies, configure CORS and HTTPS, and avoid the OWASP API risks.

    • Validate JWT bearer tokens in ASP.NET Core.
    • Write role, claim and policy based authorization.
    • Configure CORS correctly for a browser front end.
    • Recognise common API security risks such as broken object level authorization.
  8. 8. Document and version your API 25 min

    Generate OpenAPI documents with the built-in package, add an interactive UI, describe responses well, and evolve your API with versioning and deprecation.

    • Generate an OpenAPI document with AddOpenApi and MapOpenApi.
    • Add Swagger UI or Scalar for interactive docs.
    • Pick a versioning scheme and deprecate old versions politely.
    • Know which changes are breaking.
  9. 9. Performance: caching, rate limiting and resilient HTTP calls 30 min

    Make an API fast and stable under load with output caching and HybridCache, rate limiting with 429 responses, response compression, and resilient outgoing calls with IHttpClientFactory.

    • Choose between output caching and HybridCache.
    • Add rate limiting that returns 429 with Retry-After.
    • Call other services with IHttpClientFactory and resilience handlers.
    • Spot common performance mistakes in API code.
  10. 10. Test, monitor and run your API in production 30 min

    Unit and integration tests with WebApplicationFactory, health checks, structured logging, OpenTelemetry and what to watch once the API is live.

    • Write integration tests that call real endpoints in memory.
    • Expose liveness and readiness health checks.
    • Log with structure and trace requests with OpenTelemetry.
    • Prepare an API for deployment.