Documentation
¶
Overview ¶
Package httpx provides standard-library HTTP response and path primitives. It contains no authentication, logging, telemetry or transport construction; structured API error handling stays in apikit.
Index ¶
- Constants
- func ContextWithRequestID(ctx context.Context, id string) context.Context
- func NormalizePublicAPIPath(path string) string
- func RequestID(ctx context.Context) string
- func ValidRequestID(id string) bool
- func ValidTraceID(id string) bool
- func WriteJSON(w http.ResponseWriter, status int, payload any)
Constants ¶
const RequestIDHeader = "X-Request-Id"
RequestIDHeader is the request identifier carried on every API call.
Variables ¶
This section is empty.
Functions ¶
func ContextWithRequestID ¶
ContextWithRequestID returns a context that carries a validated request id. An id that fails ValidRequestID is not stored.
func NormalizePublicAPIPath ¶
NormalizePublicAPIPath strips the public API version prefix so handlers can match on /runtime/... paths whether the request arrived as /api/v1/runtime/* or legacy /api/runtime/*.
func ValidRequestID ¶
ValidRequestID reports whether id is safe to echo, log, and store.
func ValidTraceID ¶
ValidTraceID reports whether id is a W3C trace id: 32 lowercase hex digits, not all zero.
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, status int, payload any)
WriteJSON writes a JSON response with the specified status code. It sets appropriate Content-Type headers and handles JSON marshaling errors. It first marshals the payload to check for encoding errors before writing headers.
Types ¶
This section is empty.