Documentation
¶
Overview ¶
Package rest is a tiny typed-handler layer over net/http. A HandlerFunc returns an Encoder (a value that knows how to serialize itself) instead of writing to the ResponseWriter directly, which makes handlers easy to test and keeps response encoding and error handling in one place.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Encoder ¶
Encoder is a value that can serialize itself into a response body.
func JSONStatus ¶
JSONStatus wraps v as a JSON Encoder with an explicit status.
type HandlerFunc ¶
HandlerFunc handles a request and returns an Encoder describing the response. Returning a non-nil error value (e.g. *errs.Error) is the idiomatic way to signal failure — Respond will set the right status.
func ChainMiddleware ¶
func ChainMiddleware(h HandlerFunc, mw ...MidFunc) HandlerFunc
ChainMiddleware wraps h with mw in order, so mw[0] is the outermost layer.
type MidFunc ¶
type MidFunc func(HandlerFunc) HandlerFunc
MidFunc wraps a HandlerFunc to add cross-cutting behavior.