httpkit

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: BSD-3-Clause Imports: 0 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

funnyhaha.technology/httpkit

Go packages for building HTTP APIs from operations. Each endpoint is a handler around one operation, a func(context.Context, Params) (Result, error), so all the handler does is map between the wire and the operation. Every error is an RFC 9457 problem, built with funnyhaha.technology/rfc.

  • jsonhandler: a JSON endpoint from an operation. It negotiates Accept (406), checks the body's media type (415) and size (413), decodes gzip bodies, and maps the operation's declared errors to problems.
  • ssehandler: a server-sent events endpoint from a streaming operation, with keep-alives and a final error event.
  • problem: maps declared errors to problem responses, without leaking internal errors.
  • server: runs an API on a public listener and an internal one for health, readiness and pprof, with timeouts and graceful shutdown.
  • meta: serves an API's build information.
  • bearer: protects an API as an OAuth resource server. It checks bearer tokens with an operation, answers 401 and 403 with challenges that point to the RFC 9728 metadata, and serves that metadata.
  • jwks: verifies JWT access tokens (RFC 9068) against an authorization server's key set, for bearer. It's the only package that uses go-jose, so modules that don't import it don't build it.
  • ratelimit: limits requests per client IP, or per any key such as a token's subject, answering 429 with Retry-After.
  • envflag: sets flags from environment variables.
  • reqbody: opens a request body, removing gzip content codings and capping its size both as sent and as decoded.
go get funnyhaha.technology/httpkit
mux.Handle("POST /users", jsonhandler.New[createUserRequest](registerUser, newCreateUserResponse).
	WithStatus(http.StatusCreated).
	WithErrors(problem.ErrorStatus{Err: ErrUserExists, Status: rfc9110.Conflict()}).
	Handler())

err := server.New(mux).WithLogger(logger).Server().Run(ctx)

Request IDs, client IPs, request logs and CORS come from chi's middleware, httplog and go-chi/cors. echo and whatsmyip are services built with it.

Documentation is at funnyhaha.technology/oss/httpkit.

Licence

BSD 3-Clause. See LICENSE.

Documentation

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.

  • jsonhandler builds a JSON endpoint from an operation, with content negotiation, gzip bodies, body limits and error mapping.
  • ssehandler builds a server-sent events endpoint from a streaming operation.
  • problem maps an operation's declared errors to problem responses.
  • server runs an API with timeouts, health checks and graceful shutdown.
  • meta serves an API's build information.
  • bearer protects an API as an OAuth resource server, with bearer token challenges and protected resource metadata.
  • jwks verifies JWT access tokens against an authorization server's keys, for bearer.
  • ratelimit limits requests per client IP or other key.
  • envflag configures a binary from flags or environment variables.
  • reqbody opens a request body, decoding gzip and capping its size as sent and as decoded.

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.

Directories

Path Synopsis
Package 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).
Package 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).
Package 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.
Package 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.
Package jsonhandler builds an HTTP handler for a JSON endpoint from one operation: a func(context.Context, Params) (Result, error).
Package jsonhandler builds an HTTP handler for a JSON endpoint from one operation: a func(context.Context, Params) (Result, error).
Package jwks verifies JWT access tokens (RFC 9068) with the keys an authorization server publishes as a JSON Web Key Set, using go-jose.
Package jwks verifies JWT access tokens (RFC 9068) with the keys an authorization server publishes as a JSON Web Key Set, using go-jose.
Package meta serves what a running API knows about itself: its name, and the version and build of its binary.
Package meta serves what a running API knows about itself: its name, and the version and build of its binary.
Package problem writes an error as an RFC 9457 problem details response, mapping the errors an operation declares to statuses and problem types.
Package problem writes an error as an RFC 9457 problem details response, mapping the errors an operation declares to statuses and problem types.
Package 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.
Package 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.
Package 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.
Package 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.
Package server runs an HTTP API with the timeouts, health checks and graceful shutdown that every service needs.
Package server runs an HTTP API with the timeouts, health checks and graceful shutdown that every service needs.
Package ssehandler builds an HTTP handler that streams server-sent events from one streaming operation: a func(context.Context, Params) (iter.Seq2[Event, error], error).
Package ssehandler builds an HTTP handler that streams server-sent events from one streaming operation: a func(context.Context, Params) (iter.Seq2[Event, error], error).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL