Package httpkit

import "funnyhaha.technology/httpkit"
View the source code

Overview

Package httpkit is the root of a module of packages for building HTTP APIs the Funny Haha way: each endpoint is a handler around one operation, a func(context.Context, Params) (Result, error), and every error is an RFC 9457 problem.

Request IDs, client IPs, request logs and CORS come from chi's middleware, httplog and go-chi/cors, which the handlers work with.

This package itself has no API.

Subpackages

PackageDescription
funnyhaha.technology/httpkit/bearerPackage bearer protects an API as an OAuth resource server: it takes bearer access tokens (RFC 6750), verifies them with an operation, and answers a request without a good token with the challenge that tells a client where to sign in (RFC 9728).
funnyhaha.technology/httpkit/envflagPackage envflag sets command-line flags from environment variables, so a service can be configured either way: flags for development, and the environment in a container.
funnyhaha.technology/httpkit/jsonhandlerPackage jsonhandler builds an HTTP handler for a JSON endpoint from one operation: a func(context.Context, Params) (Result, error).
funnyhaha.technology/httpkit/jwksPackage jwks verifies JWT access tokens (RFC 9068) with the keys an authorization server publishes as a JSON Web Key Set, using go-jose.
funnyhaha.technology/httpkit/metaPackage meta serves what a running API knows about itself: its name, and the version and build of its binary.
funnyhaha.technology/httpkit/problemPackage problem writes an error as an RFC 9457 problem details response, mapping the errors an operation declares to statuses and problem types.
funnyhaha.technology/httpkit/ratelimitPackage ratelimit limits how many requests a client may make in a sliding window, as middleware, answering requests past the limit with 429 Too Many Requests (RFC 6585, Section 4) and Retry-After.
funnyhaha.technology/httpkit/reqbodyPackage reqbody opens a request’s body for reading: it removes the content codings in Content-Encoding and caps the body’s size, both as sent and as decoded.
funnyhaha.technology/httpkit/serverPackage server runs an HTTP API with the timeouts, health checks and graceful shutdown that every service needs.
funnyhaha.technology/httpkit/ssehandlerPackage ssehandler builds an HTTP handler that streams server-sent events from one streaming operation: a func(context.Context, Params) (iter.Seq2[Event, error], error).

Index