Documentation ¶
Overview ¶
Package rest provides HTTP types and primitives for REST requests validation and responses handling.
Index ¶
- Constants
- Variables
- func ParseHTTPArgs(r *http.Request) (tags []string, page, limit int, err error)
- func ParseHTTPArgsWithLimit(r *http.Request, defaultLimit int) (tags []string, page, limit int, err error)
- func PostProcessResponse(w http.ResponseWriter, cliCtx context.CLIContext, resp interface{})
- func ReadRESTReq(w http.ResponseWriter, r *http.Request, cdc *codec.Codec, req interface{}) bool
- func ReturnNotFoundIfNoContent(w http.ResponseWriter, data []byte, message string) bool
- func WriteErrorResponse(w http.ResponseWriter, status int, err string)
- func WriteSimulationResponse(w http.ResponseWriter, cdc *codec.Codec, gas uint64)
- type BaseReq
- type CommitTxProof
- type ErrorResponse
- type GasEstimateResponse
- type ResponseWithHeight
- type SideTxProof
Constants ¶
const ( DefaultPage = 1 DefaultLimit = 30 // should be consistent with tendermint/tendermint/rpc/core/pipe.go:19 )
Variables ¶
var ( ParseFloat64OrReturnBadRequest = rest.ParseFloat64OrReturnBadRequest ParseQueryHeightOrReturnBadRequest = rest.ParseQueryHeightOrReturnBadRequest ParseUint64OrReturnBadRequest = rest.ParseUint64OrReturnBadRequest ParseInt64OrReturnBadRequest = rest.ParseInt64OrReturnBadRequest )
Functions ¶
func ParseHTTPArgs ¶
ParseHTTPArgs parses the request's URL and returns a slice containing all arguments pairs. It separates page and limit used for pagination.
func ParseHTTPArgsWithLimit ¶
func ParseHTTPArgsWithLimit(r *http.Request, defaultLimit int) (tags []string, page, limit int, err error)
ParseHTTPArgsWithLimit parses the request's URL and returns a slice containing all arguments pairs. It separates page and limit used for pagination where a default limit can be provided.
func PostProcessResponse ¶
func PostProcessResponse(w http.ResponseWriter, cliCtx context.CLIContext, resp interface{})
PostProcessResponse performs post processing for a REST response. The result returned to clients will contain two fields, the height at which the resource was queried at and the original result.
func ReadRESTReq ¶
ReadRESTReq reads and unmarshals a Request's body to the the BaseReq stuct. Writes an error response to ResponseWriter and returns true if errors occurred.
func ReturnNotFoundIfNoContent ¶
func ReturnNotFoundIfNoContent(w http.ResponseWriter, data []byte, message string) bool
ReturnNotFoundIfNoContent returns not found error if no content
func WriteErrorResponse ¶
func WriteErrorResponse(w http.ResponseWriter, status int, err string)
WriteErrorResponse prepares and writes a HTTP error given a status code and an error message.
func WriteSimulationResponse ¶
func WriteSimulationResponse(w http.ResponseWriter, cdc *codec.Codec, gas uint64)
WriteSimulationResponse prepares and writes an HTTP response for transactions simulations.
Types ¶
type BaseReq ¶
type BaseReq struct { From string `json:"from"` Memo string `json:"memo"` ChainID string `json:"chain_id"` AccountNumber uint64 `json:"account_number"` Sequence uint64 `json:"sequence"` Fees sdk.Coins `json:"fees"` GasPrices sdk.DecCoins `json:"gas_prices"` Gas string `json:"gas"` GasAdjustment string `json:"gas_adjustment"` Simulate bool `json:"simulate"` }
BaseReq defines a structure that can be embedded in other request structures that all share common "base" fields.
func NewBaseReq ¶
func NewBaseReq( from, memo, chainID string, gas, gasAdjustment string, accNumber, seq uint64, fees sdk.Coins, gasPrices sdk.DecCoins, simulate bool, ) BaseReq
NewBaseReq creates a new basic request instance and sanitizes its values
func (BaseReq) ValidateBasic ¶
func (br BaseReq) ValidateBasic(w http.ResponseWriter) bool
ValidateBasic performs basic validation of a BaseReq. If custom validation logic is needed, the implementing request handler should perform those checks manually.
type CommitTxProof ¶
type CommitTxProof struct { Vote string `json:"vote"` Sigs string `json:"sigs"` Tx string `json:"tx"` Proof string `json:"proof"` }
CommitTxProof commit tx proof
type ErrorResponse ¶
ErrorResponse defines the attributes of a JSON error response.
func NewErrorResponse ¶
func NewErrorResponse(code int, err string) ErrorResponse
NewErrorResponse creates a new ErrorResponse instance.
type GasEstimateResponse ¶
type GasEstimateResponse struct {
GasEstimate uint64 `json:"gas_estimate"`
}
GasEstimateResponse defines a response definition for tx gas estimation.
type ResponseWithHeight ¶
type ResponseWithHeight struct { Height int64 `json:"height"` Result json.RawMessage `json:"result"` }
ResponseWithHeight defines a response object type that wraps an original response with a height.
func NewResponseWithHeight ¶
func NewResponseWithHeight(height int64, result json.RawMessage) ResponseWithHeight
NewResponseWithHeight creates a new ResponseWithHeight instance
type SideTxProof ¶ added in v0.1.7
type SideTxProof struct { Sigs [][3]string `json:"sigs"` Tx string `json:"tx"` Data string `json:"data"` }
SideTxProof side-tx proof