Last Updated: May 22, 2026
A handler is the piece of code that turns an incoming HTTP request into a response. Go's net/http package keeps that contract small: any type with a ServeHTTP(w, r) method counts as a handler. This chapter covers the http.Handler interface, the http.HandlerFunc adapter that lets a plain function satisfy that interface, the rules for writing safely to an http.ResponseWriter, and the helpers (http.Error, http.NotFound, http.Redirect) that handle the common cases for you.