HTTP Client:
*ways of doing HTTP requests
Package net/http has a layered design where each layer is a convenience wrapper on top of a lower layer.
Each lower layer is more complex but offers more control.
Here’s a recap of 3 ways of doing an HTTP GET request.
http.Get() function
Using top-level http.Get() function is the simplest but not recommended due to lack of timeouts.
http.Client.Get() method
*http.Client with &http.Client{}
Timeout
Get() or Post() or PostForm() methods
http.Client.Do() method
This allows the greatest control over the request.
http.Client and set apropriate Timeout
*http.Request with http.NewRequest
Method to "GET", "POST", "HEAD", "PUT" or "DELETE"
User-Agentwith Header.Set(key, value string)
Body of type io.ReadCloser
TransferEncoding
client.Do(req *http.Request)
req = request.WithContext(ctx)
This is the only way to do PUT or DELETE requests.