# README
What is it?
The httputil
package is a set of opinionated HTTP-related helpers.
Helpers include e.g. extracting bearer tokens from HTTP headers, retrieving parameters from the query string or parsing the HTTP body into a JSON-based struct.
Prior art
The original code was taken from Camlistore, and was available in the camlistore.org/pkg/httputil package. Lately, Camlistore has been renamed to Perkeep.
License
MIT. See LICENSE file.
# Functions
BadRequestError returns HTTP status 400 and an error message as HTML.
BearerToken extracts the Bearer token from the request.
CloseBody closes rc.
DumpRequestOut prints the request to the given io.Writer.
EqualJSON compares the two serialized byte slices for equality.
ForbiddenError returns HTTP status 403 and an error message as HTML.
FormBool checks if the request r has a Form value with the specified key that can be converted to a bool.
FormFloat64 checks if the request r has a Form value with the specified key that can be converted to a float64.
FormInt checks if the request r has a Form value with the specified key that can be converted to an int.
FormInt32 checks if the request r has a Form value with the specified key that can be converted to an int32.
FormInt64 checks if the request r has a Form value with the specified key that can be converted to an int64.
FormString checks if the request r has a Form value with the specified key.
InternalServerError returns HTTP status 500 and an error message as HTML.
IsGetOrHead returns true if r is a GET or HEAD request.
IsWebsocketUpgrade returns true if this is a WebSocket upgrade.
IsXHR returns true if r is an XHR request.
MustFormBool checks if the request r has a Form value with the specified key that can be converted to a bool.
MustFormFloat64 checks if the request r has a Form value with the specified key that can be converted to a float64.
MustFormInt checks if the request r has a Form value with the specified key that can be converted to an int.
MustFormInt32 checks if the request r has a Form value with the specified key that can be converted to an int32.
MustFormInt64 checks if the request r has a Form value with the specified key that can be converted to an int64.
MustFormString checks if the request r has a Form value with the specified key of type string.
MustParamsBool checks if the request r has a routing component with the specified key that can be converted to a bool.
MustParamsFloat64 checks if the request r has a routing component with the specified key that can be converted to a float64.
MustParamsInt checks if the request r has a routing component with the specified key that can be converted to an int.
MustParamsInt32 checks if the request r has a routing component with the specified key that can be converted to an int32.
MustParamsInt64 checks if the request r has a routing component with the specified key that can be converted to an int64.
MustParamsString checks if the request r has a routing component with the specified key.
MustQueryBool checks if the request r has a query string with the specified key that can be converted to a bool.
MustQueryDuration checks if the request r has a query string with the specified key that can be converted to a time.Duration.
MustQueryDurationWithDefault checks if the request r has a query string with the specified key that can be converted to a time.Duration.
MustQueryFloat64 checks if the request r has a query string with the specified key that can be converted to a float64.
MustQueryInt checks if the request r has a query string with the specified key that can be converted to an int.
MustQueryInt32 checks if the request r has a query string with the specified key that can be converted to an int32.
MustQueryInt64 checks if the request r has a query string with the specified key that can be converted to an int64.
MustQueryString checks if the request r has a query string with the specified key.
MustQueryTime checks if the request r has a query string with the specified key that can be converted to a time.Time, based on the given layout format.
MustQueryTimeWithDefault checks if the request r has a query string with the specified key that can be converted to a time.Time, based on the given layout format.
MustReadJSON is like ReadJSON, but panics on errors.
ParamsBool checks if the request r has a routing component with the specified key.
ParamsFloat64 checks if the request r has a routing component with the specified key that can be converted to a float64.
ParamsInt checks if the request r has a routing component with the specified key that can be converted to an int.
ParamsInt32 checks if the request r has a routing component with the specified key that can be converted to an int32.
ParamsInt64 checks if the request r has a routing component with the specified key that can be converted to an int64.
ParamsString checks if the request r has a routing component with the specified key.
QueryBool checks if the request r has a query string with the specified key that can be converted to a bool.
QueryDuration checks if the request r has a query string with the specified key that can be converted to a time.Duration.
QueryDurationWithDefault checks if the request r has a query string with the specified key that can be converted to a time.Duration.
QueryFloat64 checks if the request r has a query string with the specified key that can be converted to a float64.
QueryInt checks if the request r has a query string with the specified key that can be converted to an int.
QueryInt32 checks if the request r has a query string with the specified key that can be converted to an int32.
QueryInt64 checks if the request r has a query string with the specified key that can be converted to an int64.
QueryString checks if the request r has a query string with the specified key.
QueryStringArray checks if the request r has a query string with the specified key.
QueryTime checks if the request r has a query string with the specified key that can be converted to a time.Time, based on the given layout format.
QueryTimeWithDefault checks if the request r has a query string with the specified key that can be converted to a time.Time, based on the given layout format.
ReadJSON deserializes the body of the request into dst as JSON.
Recover can be used as a deferred func to catch panics in an HTTP handler.
RecoverJSON can be used as a deferred func to catch panics in an HTTP handler and print a JSON error.
WriteError writes an error message for display in a HTML page.
WriteJSON writes data as JSON into w with HTTP status code 200.
WriteJSONCode writes data as JSON into w and sets the HTTP status code.
WriteJSONError writes error information, serialized in a JSON structure.
# Structs
GrpcError is a placeholder for a gRPC error, and will turn it into a HTTP error.
InvalidJSONError indicates that the JSON data are invalid.
InvalidMethodError indicates that an invalid HTTP method is being used.
InvalidXSRFToken indicates that the user has not provided a valid XSRF token.
NotFoundError indicates that a record or resource does not exist.
NotImplementedError indicates that an endpoint has yet to be implemented.
TimeoutError indicates that the request has timed out.
UnauthorizedError indicates that credentials are either missing or invalid.
UnprocessableEntityError indicates that there was a semantic error in parsing a request, e.g.
# Type aliases
InvalidParameterError indicates that a parameter is invalid.
MissingParameterError indicates that a required parameter is missing or blank.
ServerError indicates any kind of internal server problem.