Skip to content

Lesson 04 · Backend & Systems with Go

Go: HTTP Services with net/http

Ground yourself in IP addresses, ports, DNS, TCP and the HTTP request-response model, then build JSON APIs with net/http: handlers, Go 1.22 method-and-path routing with PathValue, middleware, graceful shutdown and a first taste of handler testing.

50 minadvancedBackend & Systems: Go

Prerequisites: Go: Goroutines & Channels

Learning objectives
By the end of this lesson, you will be able to:
  • Explain what listening on :8080 means in terms of IP addresses and ports, and what DNS and TCP contribute beneath every HTTP call
  • Describe the HTTP request-response model: methods, path, headers, body and the status-code families
  • Write handlers with the (w http.ResponseWriter, r *http.Request) signature and register them on Go 1.22+ method-and-path patterns like GET /items/{id}, reading wildcards with r.PathValue
  • Encode and decode JSON using struct tags, json.NewEncoder and Decode - and wrap handlers with middleware shaped func(http.Handler) http.Handler
  • Serve with http.Server, shut down gracefully with Shutdown and a context, and smoke-test handlers with httptest.NewRecorder