http.Client

The Go type that sends HTTP requests and returns responses, managing connections and timeouts for you.

In more detail

Create one and reuse it so connections are pooled. Set its Timeout or pass a context with a deadline on each request; http.DefaultClient has no timeout, which can hang a tool forever. Do returns an error only for transport failures; a 500 response is not an error, so check the status code yourself.

Example

client := &http.Client{Timeout: 5 * time.Second}

Related terms

Taught in

References