{"modulePath":"github.com/ethersphere/bee","version":"v1.18.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package jsonhttp\n\nPackage jsonhttp contains utility functions that make it easier to create JSON-based HTTP APIs.\n\nPackage jsonhttp provides convenience methods to provide better JSON HTTP APIs.\n\n## Variables\n\n```go\nvar (\n\t// DefaultContentTypeHeader is the value of if \"Content-Type\" header\n\t// in HTTP response.\n\tDefaultContentTypeHeader = \"application/json; charset=utf-8\"\n\t// EscapeHTML specifies whether problematic HTML characters\n\t// should be escaped inside JSON quoted strings.\n\tEscapeHTML = false\n)\n```\n\n## Functions\n\n```go\nfunc Accepted(w http.ResponseWriter, response interface{})\n```\nAccepted writes a response with status code 202.\n\n```go\nfunc BadGateway(w http.ResponseWriter, response interface{})\n```\nBadGateway writes a response with status code 502.\n\n```go\nfunc BadRequest(w http.ResponseWriter, response interface{})\n```\nBadRequest writes a response with status code 400.\n\n```go\nfunc Conflict(w http.ResponseWriter, response interface{})\n```\nConflict writes a response with status code 409.\n\n```go\nfunc Continue(w http.ResponseWriter, response interface{})\n```\nContinue writes a response with status code 100.\n\n```go\nfunc Created(w http.ResponseWriter, response interface{})\n```\nCreated writes a response with status code 201.\n\n```go\nfunc ExpectationFailed(w http.ResponseWriter, response interface{})\n```\nExpectationFailed writes a response with status code 417.\n\n```go\nfunc Forbidden(w http.ResponseWriter, response interface{})\n```\nForbidden writes a response with status code 403.\n\n```go\nfunc Found(w http.ResponseWriter, response interface{})\n```\nFound writes a response with status code 302.\n\n```go\nfunc GatewayTimeout(w http.ResponseWriter, response interface{})\n```\nGatewayTimeout writes a response with status code 504.\n\n```go\nfunc Gone(w http.ResponseWriter, response interface{})\n```\nGone writes a response with status code 410.\n\n```go\nfunc HTTPVersionNotSupported(w http.ResponseWriter, response interface{})\n```\nHTTPVersionNotSupported writes a response with status code 505.\n\n```go\nfunc HandleBodyReadError(err error, w http.ResponseWriter) (responded bool)\n```\nHandleBodyReadError checks for particular errors and writes appropriate response accordingly. If no known error is found, no response is written and the function returns false.\n\n```go\nfunc HandleMethods(methods map[string]http.Handler, body string, contentType string, w http.ResponseWriter, r *http.Request)\n```\nHandleMethods uses a corresponding Handler based on HTTP request method. If Handler is not found, a method not allowed HTTP response is returned with specified body and Content-Type header.\n\n```go\nfunc InternalServerError(w http.ResponseWriter, response interface{})\n```\nInternalServerError writes a response with status code 500.\n\n```go\nfunc LengthRequired(w http.ResponseWriter, response interface{})\n```\nLengthRequired writes a response with status code 411.\n\n```go\nfunc MethodNotAllowed(w http.ResponseWriter, response interface{})\n```\nMethodNotAllowed writes a response with status code 405.\n\n```go\nfunc MovedPermanently(w http.ResponseWriter, response interface{})\n```\nMovedPermanently writes a response with status code 301.\n\n```go\nfunc MultipleChoices(w http.ResponseWriter, response interface{})\n```\nMultipleChoices writes a response with status code 300.\n\n```go\nfunc NewMaxBodyBytesHandler(limit int64) func(http.Handler) http.Handler\n```\nNewMaxBodyBytesHandler is an http middleware constructor that limits the maximal number of bytes that can be read from the request body. When a body is read, the error can be handled with a helper function HandleBodyReadError in order to respond with Request Entity Too Large response. See TestNewMaxBodyBytesHandler as an example.\n\n```go\nfunc NoContent(w http.ResponseWriter)\n```\nNoContent writes a response with status code 204. It does not accept a response value since the HTTP server will not write it to the client when returning a NoContent response.\n\n```go\nfunc NonAuthoritativeInfo(w http.ResponseWriter, response interface{})\n```\nNonAuthoritativeInfo writes a response with status code 203.\n\n```go\nfunc NotAcceptable(w http.ResponseWriter, response interface{})\n```\nNotAcceptable writes a response with status code 406.\n\n```go\nfunc NotFound(w http.ResponseWriter, response interface{})\n```\nNotFound writes a response with status code 404.\n\n```go\nfunc NotFoundHandler(w http.ResponseWriter, _ *http.Request)\n```\n\n```go\nfunc NotImplemented(w http.ResponseWriter, response interface{})\n```\nNotImplemented writes a response with status code 501.\n\n```go\nfunc NotModified(w http.ResponseWriter, response interface{})\n```\nNotModified writes a response with status code 304.\n\n```go\nfunc OK(w http.ResponseWriter, response interface{})\n```\nOK writes a response with status code 200.\n\n```go\nfunc PartialContent(w http.ResponseWriter, response interface{})\n```\nPartialContent writes a response with status code 206.\n\n```go\nfunc PaymentRequired(w http.ResponseWriter, response interface{})\n```\nPaymentRequired writes a response with status code 402.\n\n```go\nfunc PermanentRedirect(w http.ResponseWriter, response interface{})\n```\nPermanentRedirect writes a response with status code 308.\n\n```go\nfunc PreconditionFailed(w http.ResponseWriter, response interface{})\n```\nPreconditionFailed writes a response with status code 412.\n\n```go\nfunc PreconditionRequired(w http.ResponseWriter, response interface{})\n```\nPreconditionRequired writes a response with status code 428.\n\n```go\nfunc ProxyAuthRequired(w http.ResponseWriter, response interface{})\n```\nProxyAuthRequired writes a response with status code 407.\n\n```go\nfunc RequestEntityTooLarge(w http.ResponseWriter, response interface{})\n```\nRequestEntityTooLarge writes a response with status code 413.\n\n```go\nfunc RequestHeaderFieldsTooLarge(w http.ResponseWriter, response interface{})\n```\nRequestHeaderFieldsTooLarge writes a response with status code 431.\n\n```go\nfunc RequestTimeout(w http.ResponseWriter, response interface{})\n```\nRequestTimeout writes a response with status code 408.\n\n```go\nfunc RequestURITooLong(w http.ResponseWriter, response interface{})\n```\nRequestURITooLong writes a response with status code 414.\n\n```go\nfunc RequestedRangeNotSatisfiable(w http.ResponseWriter, response interface{})\n```\nRequestedRangeNotSatisfiable writes a response with status code 416.\n\n```go\nfunc ResetContent(w http.ResponseWriter, response interface{})\n```\nResetContent writes a response with status code 205.\n\n```go\nfunc Respond(w http.ResponseWriter, statusCode int, response interface{})\n```\nRespond writes a JSON-encoded body to http.ResponseWriter.\n\n```go\nfunc SeeOther(w http.ResponseWriter, response interface{})\n```\nSeeOther writes a response with status code 303.\n\n```go\nfunc ServiceUnavailable(w http.ResponseWriter, response interface{})\n```\nServiceUnavailable writes a response with status code 503.\n\n```go\nfunc SwitchingProtocols(w http.ResponseWriter, response interface{})\n```\nSwitchingProtocols writes a response with status code 101.\n\n```go\nfunc Teapot(w http.ResponseWriter, response interface{})\n```\nTeapot writes a response with status code 418.\n\n```go\nfunc TemporaryRedirect(w http.ResponseWriter, response interface{})\n```\nTemporaryRedirect writes a response with status code 307.\n\n```go\nfunc TooManyRequests(w http.ResponseWriter, response interface{})\n```\nTooManyRequests writes a response with status code 429.\n\n```go\nfunc Unauthorized(w http.ResponseWriter, response interface{})\n```\nUnauthorized writes a response with status code 401.\n\n```go\nfunc UnavailableForLegalReasons(w http.ResponseWriter, response interface{})\n```\nUnavailableForLegalReasons writes a response with status code 451.\n\n```go\nfunc UnprocessableEntity(w http.ResponseWriter, response interface{})\n```\nUnprocessableEntity writes a response with status code 422.\n\n```go\nfunc UnsupportedMediaType(w http.ResponseWriter, response interface{})\n```\nUnsupportedMediaType writes a response with status code 415.\n\n```go\nfunc UpgradeRequired(w http.ResponseWriter, response interface{})\n```\nUpgradeRequired writes a response with status code 426.\n\n```go\nfunc UseProxy(w http.ResponseWriter, response interface{})\n```\nUseProxy writes a response with status code 305.\n\n## Types\n\n```go\ntype MethodHandler map[string]http.Handler\n```\n\n```go\nfunc (h MethodHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)\n```\n\n```go\ntype Reason struct {\n\tField string `json:\"field\"`\n\tError string `json:\"error\"`\n}\n```\nReason represents a reason for an invalid request entry.\n\n```go\ntype StatusResponse struct {\n\tCode    int      `json:\"code,omitempty\"`\n\tMessage string   `json:\"message,omitempty\"`\n\tReasons []Reason `json:\"reasons,omitempty\"`\n}\n```\nStatusResponse is a standardized error format for specific HTTP responses. Code field corresponds with HTTP status code, and Message field is a short description of that code or provides more context about the reason for such response.\n\nIf response is string, error or Stringer type the string will be set as value to the Message field.\n\n","path":"github.com/ethersphere/bee/pkg/jsonhttp","name":"jsonhttp","synopsis":"Package jsonhttp contains utility functions that make it easier to create JSON-based HTTP APIs.","isRedistributable":true}
