The Go HTTP client
The http package in Go is a powerful library that allows you to make HTTP requests to HTTP servers and, in consequence, to your REST APIs. It is part of the standard library, so you don’t need to install anything.
As an example of its simplicity, let’s see the code needed for making a simple HTTP GET request:
resp, err := http.Get("https://example.com")
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
Quick tip: Enhance your coding experience with the AI Code Explainer and Quick Copy features. Open this book in the next-gen Packt Reader. Click the Copy button
(1) to quickly copy code into your coding environment, or click the Explain button
(2) to get the AI assistant to explain a block of code to you.
The next-gen Packt Reader is included for free with the purchase of this book. Scan the QR code OR go to packtpub.com/unlock, then use the search...