Documentation ¶
Index ¶
- type Request
- func (r *Request) BasicAuth(username, password string) *Request
- func (r *Request) Body(body io.Reader) *Request
- func (r *Request) BodyBytes(body []byte) *Request
- func (r *Request) BodyFormData(body url.Values) *Request
- func (r *Request) BodyJson(body any) *Request
- func (r *Request) BodyString(body string) *Request
- func (r *Request) BodyXML(body any) *Request
- func (r *Request) Client(client *http.Client) *Request
- func (r *Request) Context(ctx context.Context) *Request
- func (r *Request) Deadline(deadline *time.Time) *Request
- func (r *Request) Delete() (string, error)
- func (r *Request) ErrorHandler(errorHandler func(*http.Response, error) error) *Request
- func (r *Request) Get() (string, error)
- func (r *Request) Header(name, value string) *Request
- func (r *Request) Headers(headers http.Header) *Request
- func (r *Request) IfNotExpectedStatusCode(statusCode int, handler func(*http.Response) error) *Request
- func (r *Request) Method(method string) *Request
- func (r *Request) Param(name, value string) *Request
- func (r *Request) Params(params url.Values) *Request
- func (r *Request) Path(path string) *Request
- func (r *Request) Post() (string, error)
- func (r *Request) Put() (string, error)
- func (r *Request) Request() (*http.Request, context.CancelFunc, error)
- func (r *Request) Response() (resp *http.Response, cancel context.CancelFunc, err error)
- func (r *Request) ResponseBody() (body io.ReadCloser, cancel context.CancelFunc, err error)
- func (r *Request) ResponseBuffer() (*bytes.Buffer, error)
- func (r *Request) ResponseBytes() ([]byte, error)
- func (r *Request) ResponseJson(v any) error
- func (r *Request) ResponseString() (string, error)
- func (r *Request) ResponseXML(v any) error
- func (r *Request) StatusCodeHandler(statusCode int, handler func(*http.Response) error) *Request
- func (r *Request) Timeout(timeout time.Duration) *Request
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is an internal "staging" struct used when we want to track of what kind of Request user wants to make.
func URL ¶
URL will start building a request with the given URL (scheme+domain), an example is `https://go.dev` (notice without the path or parameters).
func (*Request) BasicAuth ¶
BasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.
func (*Request) BodyFormData ¶
BodyFormData will take values and send them as formdata.
func (*Request) BodyJson ¶
BodyXML will encode given interfact/instance into JSON and use that as body.
func (*Request) BodyString ¶
BodyString will use string as body.
func (*Request) BodyXML ¶
BodyXML will encode given interfact/instance into XML and use that as body.
func (*Request) Deadline ¶
Deadline for the request (absolute time), defaults to `nil` (no deadline).
func (*Request) ErrorHandler ¶
ErrorHandler will set the error handler to be called if the request fails.
func (*Request) Header ¶ added in v0.2.0
Headers will record headers to use in the request, will override defaults.
func (*Request) Headers ¶
Headers will record headers to use in the request, will override defaults.
func (*Request) IfNotExpectedStatusCode ¶ added in v0.2.0
func (r *Request) IfNotExpectedStatusCode(statusCode int, handler func(*http.Response) error) *Request
IfNotExpectedStatusCode will set the handler to be called if the request does not return the expected status code.
func (*Request) Method ¶
Method to use in HTTP request, defaults to "GET" -- recommend using `http.Method...` constants.
func (*Request) ResponseBody ¶
func (r *Request) ResponseBody() (body io.ReadCloser, cancel context.CancelFunc, err error)
Make a request (parked) and get the body reader (needs closing) with cancel.
func (*Request) ResponseBuffer ¶
Make a request and get the response as `*bytes.Buffer`.
func (*Request) ResponseBytes ¶
Make a request and get the response as bytes.
func (*Request) ResponseJson ¶
Make a request and decode the JSON response into given interface.
func (*Request) ResponseString ¶
Make a request and get the response as a string.
func (*Request) ResponseXML ¶
Make a request and decode the XML response into given interface.
func (*Request) StatusCodeHandler ¶ added in v0.2.0
StatusCodeHandler will set the handler to be called if the request returns given status code.