kit-go-http-api
Implement or change HTTP handlers in a Go service following the project's router and patterns (net/http, chi, gin, or echo), with input validation, context propagation, correct status codes and JSON e
SKILL.mdregistry/skills/go-http-api/SKILL.md
GitHubGo HTTP API implementation
1. Learn the service's structure
- Find the router (
http.ServeMuxwith method and wildcard patterns, which needgo 1.22or later ingo.mod; chi, gin, echo), how handlers are registered and grouped, and how dependencies such as the store and logger reach handlers (a server struct, closures). - Note existing middleware for authentication, request IDs, logging, and recovery, the JSON helpers and error response shape, and how tests build the server.
- Read an existing handler and its test, and follow them.
2. Implement the handler
- Register the route with its method next to related routes. Parse path values (
r.PathValue,chi.URLParam) and query parameters, and validate them: return 400 with the project's error shape for bad input. - Decode JSON bodies with a size limit (
http.MaxBytesReader) andDisallowUnknownFieldswhere the project does; reject trailing data. Validate required fields. - Use separate request and response structs with
jsontags so internal fields such as password hashes are never encoded. - Pass
r.Context()to every store and outbound call. Map domain errors (errors.Is(err, store.ErrNotFound)) to 404 and similar; log unexpected errors and return 500 without leaking details. - Set
Content-Typeand the status code before writing the body, and do not write the header twice. Return right after writing an error response. - Apply the project's authentication middleware to anything not explicitly public. If no authentication exists and the endpoint exposes user data, say so and ask before shipping it unprotected.
3. Test
- Use
httptest.NewRecorderwith the real router (orhttptest.NewServer) and table-driven cases: success and response shape, validation failures (400), missing resources (404), and authorization failures where relevant. - Run
go test ./...(with-raceif the project uses it) andgo vet ./....
4. Report
Summarize the routes added or changed, request and response types, error mapping, tests and their results, and assumptions, such as authentication decisions, that the user should confirm.
Examples
- Use: "Add a POST /users/{id}/deactivate endpoint." "Add pagination to GET /orders."
- Skip: "Review handlers.go." (code review) "Add a gRPC method." (other transport)