http.Handler

In Go, a function or type that receives an HTTP request and writes the response, with the signature func(w http.ResponseWriter, r *http.Request).

In more detail

A ServeMux calls the right handler for each path, and the server runs each request's handler in its own goroutine. Keep handlers small: read the request, call your logic, write a status and body. They can be tested in memory with httptest.

Example

func health(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintln(w, "ok")
}

Related terms

Taught in

References