Documentation
¶
Overview ¶
Package stahp provides enablement mechanisms for marshaling HTTP requests to strongly-typed handlers functions and marshaling the results back as a response.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NoReqParser ¶
NoReqParser is a convenience function to satisfy the requirement for a RequestParser when marshaling requests to a NoReqParser.
func Route ¶
func Route[Req any, Resp any]( target Target[Req, Resp], parser RequestParser[Req], responder Responder[Resp], ) http.HandlerFunc
Route generates an http.HandlerFunc from a RequestParser, a Target, and a Responder.
Types ¶
type NoReqTarget ¶
A NoReqTarget is a function that can be used with NoReq to create a Target that doesn't need any input from the HTTP request.
type RequestParser ¶
A RequestParser extracts a strongly-typed request from an HTTP request.
type Responder ¶
type Responder[Resp any] interface { // Write marshals responses from a [Target] to an HTTP response. Write(Resp, http.ResponseWriter, *http.Request) // WriteParseErr marshals errors that occur parsing an HTTP request. WriteParseErr(error, http.ResponseWriter, *http.Request) // WriteErr marshals errors from [Target] to an HTTP response. WriteErr(error, http.ResponseWriter, *http.Request) }
A Responder marshals responses and errors to an HTTP response.
func NewResponder ¶
func NewResponder[Resp any]( write ResponseWriter[Resp], writeParseErr ResponseWriter[error], writeErr ResponseWriter[error], ) Responder[Resp]
NewResponder builds a Responder from a ResponseWriter for each
type ResponseWriter ¶
type ResponseWriter[T any] func(T, http.ResponseWriter, *http.Request)
A ResponseWriter marshals a value to an HTTP response.
type Target ¶
A Target is a strongly-typed function taking a request and returning a response or an error. Marshaling instances of HTTP requests to a Target and marshaling the response or the error back as a response is the mission of the stahp package.
func NoReq ¶
func NoReq[Resp any](target NoReqTarget[Resp]) Target[struct{}, Resp]
NoReq builds a Target from a NoReqTarget.