0PricingLogin
Go Academy · Lesson

Making HTTP Requests

GET, POST with http.NewRequest and http.DefaultClient

http.Get shortcut

http.Get(url) is the simplest way to make a GET request. Always close the response body.

resp, err := http.Get("https://api.example.com/users")
if err != nil { return err }
defer resp.Body.Close()

http.DefaultClient

http.Get uses the package-level DefaultClient. For production, create a custom client with timeouts set.

client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Get(url)

All lessons in this course

  1. Making HTTP Requests
  2. Setting Timeouts and Headers
  3. Decoding JSON Responses
  4. Error Handling and Retry Logic
← Back to Go Academy