Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
HTTP Clients in Go: http.Client, Timeouts, Cancellation with context, Reusing the Transport and Retries
In Go, http.DefaultClient has no timeout; in production you use one shared http.Client, Transport timeouts for each phase, Client.Timeout per attempt and a context for the total budget. Which timeout covers which phase, Go 1.27 reading small bodies on Close to reuse the connection, MaxIdleConnsPerHost, checking 4xx/5xx, retries with backoff, jitter and Retry-After, idempotency, and testing a client with httptest.
HTTP Servers with net/http: ServeMux Pattern Routing, Handlers, Middleware and Timeouts
For an HTTP service in Go the standard library is enough: since 1.22 ServeMux matches method and wildcard patterns with a most-specific-wins rule, and middleware is an ordinary function that wraps a handler. Moving the Bookstore API into the httpapi package, RequestID and Logging middleware, CORS and CrossOriginProtection, the 307 redirect, the pattern conflict panic, WriteTimeout not stopping the handler, and http.Server timeouts against slowloris.
A Bare HTTP Server with node:http: Request/Response, Hand-Rolled Routing and Why You Need a Framework
node:http is the lowest layer of HTTP in Node: reading the body with a size limit, routing, validation and error handling are your job, and a single error in an async handler can take the process down. With real output: the crashing server, a JSON body read as a stream with 413/415/422 responses, a hand-rolled router, a worker stopped when the client leaves, listen() binding to ::, headersTimeout answering slowloris with 408, and a connection left open after a 413.