Table of Contents

HTTP Client (net/http)

What is it?

An HTTP client is code that sends HTTP requests to a server and reads HTTP responses back.

In Go, the standard library package `net/http` provides:

What is it used for?

Core building blocks

Minimal example (GET)

package main
 
import (
    "io"
    "log"
    "net/http"
)
 
func main() {
    resp, err := http.Get("https://example.com")
    if err != nil {
        log.Fatal(err)
    }
    defer resp.Body.Close()
 
    b, _ := io.ReadAll(resp.Body)
    log.Println("status:", resp.Status)
    log.Println("bytes:", len(b))
}

Best practices (important)

Hard words (English)