The net/http package
The net/http
package offers functions that allow you to develop web servers and clients. For example, http.Get()
and http.NewRequest()
are used by clients to make HTTP requests, whereas http.ListenAndServe()
is used to start web servers by specifying the IP address and the TCP port that the server listens to. Additionally, http.HandleFunc()
defines supported URLs as well as the functions that are going to handle these URLs.
The next three subsections describe three important data structures of the net/http
package—you can use these descriptions as a reference while reading this chapter.
The http.Response type
The http.Response
struct embodies the response from an HTTP request—both http.Client
and http.Transport
return http.Response
values once the response headers have been received. Its definition can be found at https://go.dev/src/net/http/response.go:
type Response struct {
Status string // e.g. "200 OK"
StatusCode...