net/http

Network
import "net/http"

Provides HTTP client and server implementations. The foundation of web development in Go.

Example

package main

import (
    "fmt"
    "net/http"
)

func main() {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "Hello!")
    })
    http.ListenAndServe(":8080", nil)
}

Key Types & Functions

HandlerHandleFuncListenAndServeGetClientRequestResponseServeMux

About net/http

The net/http package (imported as net/http) belongs to the Network category of Go packages. Provides HTTP client and server implementations. The foundation of web development in Go.

Go's standard library is one of the language's greatest strengths, providing production-ready implementations for networking, cryptography, encoding, I/O, and more. The net/http package follows Go's philosophy of simplicity and composability — small, focused packages that combine through interfaces like io.Reader and io.Writer.

When using net/http in production, follow Go best practices: handle errors explicitly, use context for cancellation and timeouts, prefer composition over inheritance, and write table-driven tests. The Go documentation at pkg.go.dev provides comprehensive API references and examples for every exported type and function.

Related Packages