Documentation ¶
Overview ¶
Package requests is an elegant and simple HTTP library for golang, built for human beings.
This package mimics the implementation of the classic Python package Requests(https://requests.readthedocs.io/)
Index ¶
- func SetEnvTimeout(timeout time.Duration)
- type Option
- func BasicAuth(username, password string) Option
- func Body(body io.Reader) Option
- func Data(data any) Option
- func DisableKeepAlives() Option
- func Dump(req, resp *string) Option
- func Files(files map[string]*os.File) Option
- func Form(form map[string]string) Option
- func FormPairs(kv ...string) Option
- func HeaderPairs(kv ...string) Option
- func Headers(headers map[string]string) Option
- func JSON(v any) Option
- func ParamPairs(kv ...string) Option
- func Params(params map[string]string) Option
- func Timeout(timeout time.Duration) Option
- func ToJSON(v any) Option
- func ToText(v *string) Option
- type Response
- func Delete(url string, options ...Option) (*Response, error)
- func Get(url string, options ...Option) (*Response, error)
- func Patch(url string, options ...Option) (*Response, error)
- func Post(url string, options ...Option) (*Response, error)
- func Put(url string, options ...Option) (*Response, error)
- func (r *Response) Bytes() []byte
- func (r *Response) Cookies() map[string]*http.Cookie
- func (r *Response) Headers() http.Header
- func (r *Response) JSON(v any) error
- func (r *Response) Method() string
- func (r *Response) StatusCode() int
- func (r *Response) Text() string
- func (r *Response) URL() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetEnvTimeout ¶ added in v0.0.7
SetEnvTimeout sets the default timeout for each HTTP request at the environment level.
Types ¶
type Option ¶
type Option func(*httpOptions)
Option is the functional option type.
func DisableKeepAlives ¶ added in v0.1.2
func DisableKeepAlives() Option
DisableKeepAlives, if true, disables HTTP keep-alives and will only use the connection to the server for a single HTTP request.
This is unrelated to the similarly named TCP keep-alives.
func Dump ¶ added in v0.2.2
Dump dumps outgoing client request and response to the corresponding input param (req or resp) if not nil.
Refer: - https://pkg.go.dev/net/http/httputil#DumpRequestOut - https://pkg.go.dev/net/http/httputil#DumpResponse
func Files ¶ added in v0.1.0
Files sets files to a map of (field, fileHandler). It also sets the Content-Type as "multipart/form-data".
func Form ¶
Form sets the given form into the request body. It also sets the Content-Type as "application/x-www-form-urlencoded".
func FormPairs ¶
FormPairs sets form by the mapping of key, value ... Pairs panics if len(kv) is odd.
func HeaderPairs ¶
HeaderPairs sets HTTP headers formed by the mapping of key, value ... Pairs panics if len(kv) is odd.
func JSON ¶
JSON marshals the given struct as JSON into the request body. It also sets the Content-Type as "application/json".
func ParamPairs ¶
ParamPairs returns an Params formed by the mapping of key, value ... Pairs panics if len(kv) is odd.
func Timeout ¶ added in v0.0.7
Timeout specifies a time limit for requests made by this Client. The timeout includes connection time, any redirects, and reading the response body. The timer remains running after Get, Head, Post, or Do return and will interrupt reading of the Response.Body.
A Timeout of zero means no timeout. Default is 60s.
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response is a wrapper of HTTP response.
func Delete ¶
Delete sends an HTTP request with DELETE method.
On error, any Response can be ignored. A non-nil Response with a non-nil error only occurs when Response.StatusCode() is not 2xx.
func Get ¶
Get sends an HTTP request with GET method.
On error, any Response can be ignored. A non-nil Response with a non-nil error only occurs when Response.StatusCode() is not 2xx.
func Patch ¶ added in v0.1.0
Patch sends an HTTP request with PATCH method.
On error, any Response can be ignored. A non-nil Response with a non-nil error only occurs when Response.StatusCode() is not 2xx.
func Put ¶
Put sends an HTTP request with PUT method.
On error, any Response can be ignored. A non-nil Response with a non-nil error only occurs when Response.StatusCode() is not 2xx.
func (*Response) Cookies ¶ added in v0.0.9
Cookies parses and returns the cookies set in the Set-Cookie headers.
func (*Response) Headers ¶ added in v0.0.9
Headers maps header keys to values. If the response had multiple headers with the same key, they may be concatenated, with comma delimiters.
func (*Response) StatusCode ¶
StatusCode returns status code of HTTP response.