Module lessons (5/5)
Mini-project: a server HTTP
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 andWriteHeader. - Configure REST routes with method and path variables on
*http.ServeMux(r.PathValue). - Compose reusable middleware as
func(http.Handler) http.Handlerwrappers. - Protect the production server with
&http.Server(explicit timeouts) and graceful shutdown usingsrv.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
- 1Handler signature and header order
- 2Routing with
*http.ServeMux(Go 1.22+) - 3Middleware as decorators
- 4Safety Timeout and Graceful Shutdown
- 5Guided practice
- 6Check for understanding
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.