Documentation
¶
Overview ¶
Package request provides the implementation of operations related to a http and cmd request it gives the features like reading parameters, bind request body, etc.
Index ¶
- func NewMock(method, target string, body io.Reader) (*http.Request, error)
- type CMD
- func (c *CMD) Bind(i interface{}) error
- func (c *CMD) BindStrict(i interface{}) error
- func (c *CMD) GetClaim(string) interface{}
- func (c *CMD) GetClaims() map[string]interface{}
- func (c *CMD) Header(key string) string
- func (c *CMD) Param(key string) string
- func (c *CMD) Params() map[string]string
- func (c *CMD) PathParam(key string) string
- func (c *CMD) Request() *http.Request
- type HTTP
- func (h *HTTP) Bind(i interface{}) error
- func (h *HTTP) BindStrict(i interface{}) error
- func (h *HTTP) Body() ([]byte, error)
- func (h *HTTP) GetClaim(claimKey string) interface{}
- func (h *HTTP) GetClaims() map[string]interface{}
- func (h *HTTP) Header(key string) string
- func (h *HTTP) Method() string
- func (h *HTTP) Param(key string) string
- func (h *HTTP) ParamNames() []string
- func (h *HTTP) Params() map[string]string
- func (h *HTTP) PathParam(key string) string
- func (h *HTTP) Request() *http.Request
- func (h *HTTP) String() string
- func (h *HTTP) URI() string
- type Request
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CMD ¶
type CMD struct {
// contains filtered or unexported fields
}
CMD (Command) is a data structure designed to access and manage various types of parameters, including path parameters, query parameters, and request bodies, used in command-line (cmd) applications.
It provides a simple and structured way to work with input parameters and data, making it easier to handle and process command-line input.
func (*CMD) BindStrict ¶
BindStrict is an alias for Bind.
type HTTP ¶
type HTTP struct {
// contains filtered or unexported fields
}
HTTP represents a utility for accessing and performing HTTP operations, such as reading an HTTP request and gathering information related to the request, including path parameters.
The `HTTP` type provides a convenient interface for working with HTTP requests, extracting data from them, and processing related information. It is particularly useful for building applications that interact with the HTTP protocol and need to extract data from incoming requests.
func (*HTTP) Bind ¶
Bind checks the Content-Type to select a binding encoding automatically. Depending on the "Content-Type" header different bindings are used: - XML binding is used in case of: "application/xml" or "text/xml" - JSON binding is used by default It decodes the json payload into the type specified as a pointer. It returns an error if the decoding fails.
func (*HTTP) BindStrict ¶
BindStrict checks the "Content-Type" header to select a binding encoding automatically. Depending on the "Content-Type" header, different bindings are used: - XML binding is used in case of "application/xml" or "text/xml" content type. - JSON binding is used by default. It decodes the JSON or XML payload into the type specified as a pointer. It returns an error if the decoding fails, and it disallows unknown fields when decoding JSON payloads to enforce strict parsing.
func (*HTTP) ParamNames ¶
ParamNames returns the list of query parameters (keys) for the current request
func (*HTTP) Params ¶
Params returns the query parameters for the current request in the form of a mapping of key to it's values as comma separated values
type Request ¶
type Request interface {
Request() *http.Request
Params() map[string]string
Param(string) string
PathParam(string) string
Bind(interface{}) error
BindStrict(interface{}) error
Header(string) string
GetClaims() map[string]interface{}
GetClaim(string) interface{}
}
Request provides the methods that are related to an incoming HTTP request
func NewHTTPRequest ¶
NewHTTPRequest injects a *http.Request into a gofr.Request variable