Free course · 12 lessons · Intermediate

Go Web Frameworks: net/http, Chi, Gin, Echo and Fiber

Build the same JSON API with the Go standard library and the four most popular Go web frameworks, then learn the parts every real service needs: middleware, validation and errors, testing, database access, configuration, structured logging and graceful shutdown. Every example is a real program whose requests and responses are shown, so you can compare the frameworks side by side and choose with confidence.

Start the course

1. The Standard Library and the Big Four

Build the same small JSON API five ways: with net/http alone, then Chi, Gin, Echo and Fiber, so you see exactly what each framework adds and what it changes.

  1. Start with net/http: What the Standard Library Already Does — Since Go 1.22 the standard library router matches methods and path parameters, so many APIs need no framework at all. Build a JSON endpoint, add middleware, and learn the Handler interface every Go framework builds on.
  2. Chi: A Router That Stays Close to net/http — Chi adds route groups, sub-routers, URL parameters and a set of ready middleware while keeping the standard http.Handler signature, so every net/http middleware and handler works unchanged.
  3. Gin: The Most Popular Go Web Framework — Gin gives you a fast router, a Context with helpers for JSON, binding and validation of request bodies with struct tags, route groups and middleware. Build the books API the Gin way.
  4. Echo: Handlers That Return Errors — Echo's handlers return an error, and one central HTTPErrorHandler turns every error into a response. Build the books API with Echo v5: binding, a pluggable validator, groups and built-in middleware.
  5. Fiber: Express-Style Go on fasthttp — Fiber feels like Express.js and is built on fasthttp for raw speed. Build the books API with Fiber v3, and learn the trade-offs: it isn't net/http, and its context values are reused between requests.

2. Building Production APIs in Go

The parts every real service needs whichever framework you pick: middleware, validation and consistent errors, tests, database access, logging, timeouts and graceful shutdown. Then how to choose a framework, and a capstone.

  1. Middleware: Logging, Auth, Recovery and Request IDs — Write the middleware every API needs and learn the onion model: each layer runs code before and after the next one. Order matters: recovery first, then request IDs, logging, auth and rate limits.
  2. Validation and Consistent Error Responses — Validate request bodies with struct tags, turn validator errors into clear per-field messages, and return every error in one predictable JSON shape with the right status code.
  3. Testing Go APIs with httptest — Write table-driven tests that send real requests to your router in memory, check status codes and JSON bodies, and swap the database for a fake through an interface. No running server needed.
  4. Database Access: database/sql, Repositories and Transactions — Talk to SQL databases with database/sql: connection pools, parameterised queries, scanning rows, transactions and context timeouts, behind a small repository interface. Compare GORM, sqlx and sqlc.
  5. Production Ready: Config, Logging, Timeouts and Graceful Shutdown — Turn a working API into a service you can operate: configuration from the environment, structured logs with log/slog, server timeouts, health checks, and graceful shutdown that lets in-flight requests finish.
  6. Choosing a Go Framework (or None) — Compare net/http, Chi, Gin, Echo and Fiber on what actually matters: compatibility, features, error handling, ecosystem and team familiarity. Raw benchmark speed rarely decides it.
  7. Capstone: Build a Bookmarks API — Build a complete REST API for saving bookmarks with the framework of your choice: validation, auth, pagination, a database, tests and graceful shutdown. Then review it against the rubric.

Was this page helpful?