How I Write HTTP Web Services After 8 Years
summary
Concrete Go patterns for production HTTP services: no global state, server struct with dependencies, centralize routing in routes.go and return handler closures so each endpoint has its own request/response types and lazy setup via sync.Once. Prefer handlerFunc/Handler types, factor respond/decode helpers, wire middleware explicitly, and use net/http/httptest to run isolated handler unit tests or full-stack ServeHTTP tests. These choices trade a bit more boilerplate for maintainability and testability.
AI-written summary · about
chapters (19)
- 0:00Intro
- 3:16How to use this talk
- 4:16I tend to select for...
- 6:40Let's jump in...
- 7:34Constructor for server?
- 9:17Handlers hang off the server
- 10:16Naming handler methods
- 10:48Return the handler
- 11:35Take arguments for handler
- 12:47HandlerFunc over Handler
- 14:14Middleware are just Go functions
- 15:01Wire Middleware up in routes.go
- 15:40Abstract responding
- 16:37Abstract decoding
- 17:32Request and response data types
- 19:06Test types help frame the test
- 21:44Make server an http.Handler
- 22:33server is testable
- 23:35Middleware are testable too








