Skip to main content
Module 10 · Lesson 5 of 550/50 in the course~18 min
Module lessons (5/5)

Mini-project: a server HTTP

Lesson preview5 hands-on exercises readyCourse Go · Module 10 — Idiomatic practice

net/http, minimal handler and router, middleware as decorator, graceful shutdown with context.

What you'll learn in this lesson

  • Implement handler according to the canonical signature func(w http.ResponseWriter, r *http.Request) respecting the order between header and WriteHeader.
  • Configure REST routes with method and path variables on *http.ServeMux (r.PathValue).
  • Compose reusable middleware as func(http.Handler) http.Handler wrappers.
  • Protect the production server with &http.Server (explicit timeouts) and graceful shutdown using srv.Shutdown(ctx).

Overview

The net/http standard library package includes everything you need to build secure and scalable HTTP APIs without depending on heavy frameworks: routers with method and path parameter matching (since Go 1.22+), middleware such as decorated functions, anti-Slowloris timeouts, and graceful shutdown tied to context.Context.

Each HTTP handler receives w http.ResponseWriter (to send header, status code and body) and r *http.Request (to read method, URL, body and r.Context()):

Sections covered in this lesson

  1. 1Handler signature and header order
  2. 2Routing with *http.ServeMux (Go 1.22+)
  3. 3Middleware as decorators
  4. 4Safety Timeout and Graceful Shutdown
  5. 5Guided practice
  6. 6Check for understanding
Pro Lesson · Module 10 — Idiomatic practice

Unlock "Mini-project: a server HTTP" and the full Course Go curriculum

`net/http`, minimal handler and router, middleware as decorator, graceful shutdown with context.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course Go plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.