net/http
Go's standard library package for HTTP, providing both a production-ready web server and an HTTP client.
In more detail
The client side sends requests with http.Client; the server side routes requests to handlers with http.ServeMux and serves them with http.Server. Many Go services use nothing else for HTTP.
Example
import "net/http"Related terms
- http.Client — The Go type that sends HTTP requests and returns responses, managing connections and timeouts for you.
- 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).
- http.Server — The Go type that listens on a network address and serves HTTP requests through a handler, with fields for limits such as timeouts.
- http.ServeMux — The request router in Go's net/http package, which matches each request's path, and optionally its method, to the handler registered for it.
- httptest — Go's standard library package of helpers for testing HTTP code, such as a recorder that captures what a handler writes.
Taught in
- Calling APIs with net/http Client — Concurrent Systems Programming with Go
- Serving HTTP with net/http Server — Concurrent Systems Programming with Go
- Graceful Shutdown on SIGTERM — Concurrent Systems Programming with Go