Build a Go Web API that goes beyond “Hello, World”
Getting a REST API running in Go is easy.
Building one that is structured well, handles concurrent requests correctly, manages database changes safely, can be tested, containerized, documented, and deployed is where things become interesting.
Building Production Web APIs with Go takes you through that journey step by step.
You begin with a tiny HTTP server and gradually develop it into a complete library API backed by PostgreSQL. Rather than presenting a finished architecture and asking you to copy it, the book introduces problems as the application grows, then shows how to solve them. You see not only what the final code looks like, but why the design changes are necessary.
Along the way, you will learn how to:
- Build RESTful HTTP APIs using Go,
net/http, and Chi - Work directly with PostgreSQL using pgx
- Generate type-safe database code from SQL with sqlc
- Manage schema changes with Goose migrations
- Separate HTTP models from database models
- Structure a Go backend for maintainability
- Handle transactions, row locking, and concurrent requests safely
- Enforce data integrity with PostgreSQL constraints
- Write unit tests using database abstractions and test doubles
- Understand what unit tests cannot prove without a real database
- Document your API with OpenAPI and Swagger UI
- Package the application with Docker and Docker Compose
- Implement graceful shutdown
- Deploy the complete application to Kubernetes
The example application is deliberately realistic. A seemingly simple operation—allowing a user to borrow a book—eventually exposes concurrency problems and leads naturally to transactions, PostgreSQL row-level locking, and database constraints. The emphasis throughout is on understanding the engineering decisions behind the code rather than simply copying recipes.
Who is this book for?
This book is for developers who already know the basics of Go and SQL and want to learn how the pieces of a real backend application fit together.
It is not a beginner’s introduction to the Go language, nor is it a comprehensive reference to PostgreSQL, Docker, or Kubernetes. Instead, it concentrates on the practical decisions involved in taking a small Go application toward a production-oriented architecture.
If you can write basic Go programs and understand simple SQL queries, this book will help you make the transition from “I can build an API” to “I understand how to engineer a backend.”