The net/http Package

Let’s learn about the net/http package.

The net/http package offers functions that allow us 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—we 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. We can look at its definition for more details.

Get hands-on with 1200+ tech skills courses.