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 for making HTTP requests, whereas http.ListenAndServe()
is used for starting web servers by specifying the IP address and the TCP port 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
structure 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://golang.org/src/net/http/response.go:
type Response struct {
Status string // e.g. "200 OK"...