http.ResponseWriter

The Go interface a handler uses to send its response: set headers, write the status code with WriteHeader, then write the body.

In more detail

The order matters: headers first, then status, then body. If you write the body without calling WriteHeader, the status is 200. It is an io.Writer, so fmt.Fprintln and json encoders can write to it directly.

Example

w.WriteHeader(http.StatusServiceUnavailable)

Related terms

Taught in

References