[Go] Send an HTTP GET request

Created on November 30, 2026

Use net/http to send an HTTP request. This example sends a GET request to https://documentroot.org, reads the complete response body, and prints it.

package main

import (
    "fmt"
    "io/ioutil"
    "net/http"
)

func main() {
    request, err := http.NewRequest("GET", "https://documentroot.org", nil)
    if err != nil {
        fmt.Println(err.Error())
    }

    client := &http.Client{}

    response, err := client.Do(request)
    if err != nil {
        fmt.Println(err.Error())
    }
    defer response.Body.Close()

    responseBody, err := ioutil.ReadAll(response.Body)
    if err != nil {
        fmt.Println(err.Error())
    }

    fmt.Print(string(responseBody))
}

The third argument to http.NewRequest supplies the request body. Pass nil for a request with no body.

Go