GoAPIREST
Building REST APIs with Go
A pragmatic look at designing robust and scalable REST APIs in Go using the standard library and a thin router.
April 20, 2026 · 1 min read
Building a REST API in Go doesn't require a heavy framework. The standard library gets you surprisingly far, and a small router on top keeps things clean without hiding what's happening.
Why the standard library goes a long way
net/http in Go 1.22+ supports method-based routing and path parameters out of the box. For many services, that's enough.
package main
import (
"encoding/json"
"net/http"
)
type User struct {
ID string `json:"id"`
Name string `json:"name"`
}
func main() {
mux := http.NewServeMux()
mux.HandleFunc("GET /users/{id}", func(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
json.NewEncoder(w).Encode(User{ID: id, Name: "Alain"})
})
http.ListenAndServe(":8080", mux)
}
Middleware as plain functions
Middleware is just func(http.Handler) http.Handler. No magic, no adapters.
func logging(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Printf("%s %s", r.Method, r.URL.Path)
next.ServeHTTP(w, r)
})
}
Keep handlers thin
Handlers should decode, delegate to a service, and encode. Business logic belongs elsewhere — it makes testing far easier.
That's the core of a maintainable API in Go: small pieces, explicit wiring, no surprises.