HTTP handler

An HTTP handler is a component that receives an HTTP request and writes an HTTP response. In Go's net/http package, a handler implements the ServeHTTP method defined by http.Handler.

Minimal example

go
func health(w http.ResponseWriter, r *http.Request) {
    w.WriteHeader(http.StatusOK)
    _, _ = w.Write([]byte("ok"))
}

Learn this concept

Lesson 1.16 · net/http handlers and middleware

Used in exercises

Exercise 1.18 · RateLimit HTTP middleware that returns 429 Exercise 1.19 · chi server with /healthz and a rate limit Exercise 5.7 · Rider presence service Exercise 6.2 · Menu cache and stock updater Exercise 6.14 · Admin order statistics
Prerequisite conceptsGo functionsGo errors