Documentation ¶
Index ¶
- Variables
- func BodyAsBytes(r io.ReadCloser) ([]byte, error)
- func BodyAsString(r io.ReadCloser) (string, error)
- type Option
- func Accept(accept string) Option
- func ApiKey(key string) Option
- func BasicAuth(username, password string) Option
- func Bearer(bearer string) Option
- func Callback(cb func(*Response)) Option
- func Client(client *http.Client) Option
- func Context(ctx context.Context) Option
- func CookieJar(jar http.CookieJar) Option
- func Cookies(cookies []*http.Cookie) Option
- func Data(data interface{}) Option
- func DisallowRedirects() Option
- func File(fieldName, filepath string, params map[string]string) Option
- func FormData(form map[string]string) Option
- func Headers(headers map[string]string) Option
- func Json(v interface{}) Option
- func OAuth2(cfg *oauth2.Config, tok *oauth2.Token) Option
- func RequestModifier(modifier func(*http.Request)) Option
- func Timeout(timeout time.Duration) Option
- func UserAgent(agent string) Option
- type Response
- func Delete(url string, opts ...Option) (*Response, error)
- func Do(method, url string, opts ...Option) (*Response, error)
- func Get(url string, opts ...Option) (*Response, error)
- func Head(url string, opts ...Option) (*Response, error)
- func Patch(url string, opts ...Option) (*Response, error)
- func Post(url string, opts ...Option) (*Response, error)
- func Put(url string, opts ...Option) (*Response, error)
- func (r *Response) Body() io.ReadCloser
- func (r *Response) ContentLength() int64
- func (r *Response) ContentType() string
- func (r *Response) Cookies() []*http.Cookie
- func (r *Response) Encoding() []string
- func (r *Response) Headers() map[string]string
- func (r *Response) Raw() *http.Response
- func (r *Response) Status() string
- func (r *Response) StatusCode() int
Constants ¶
This section is empty.
Variables ¶
var ErrRequestBodySetMultipleTimes = errors.New("you have set the request body more than once")
The error thrown when you attempt to set the HTTP request body more than once
Functions ¶
func BodyAsBytes ¶ added in v0.1.2
func BodyAsBytes(r io.ReadCloser) ([]byte, error)
The response body as a byte slice. Bear in mind that the response body can only be read once.
func BodyAsString ¶ added in v0.1.2
func BodyAsString(r io.ReadCloser) (string, error)
The response body as a string. Bear in mind that the response body can only be read once.
Types ¶
type Option ¶ added in v0.1.3
type Option func(*options)
func Context ¶ added in v0.1.1
Pass a context into the HTTP request (allows for request cancellation, for example).
func Data ¶
func Data(data interface{}) Option
Add any interface{} that can be serialized to a []byte and apply a "Content-Type: application/octet-stream" header.
func FormData ¶
Add key/value form data to the request body and apply a "Content-Type: application/x-www-form-urlencoded" header.
func Json ¶
func Json(v interface{}) Option
Add any interface{} that can be marshaled as JSON to the request body and apply a "Content-Type: application/json;charset=utf-8" header.
func RequestModifier ¶ added in v0.1.1
Applies a user-provided request modification function. Applied after all other request modifications have been made by the selected options.
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
A struct containing the relevant response information returned by a rek request.
func Do ¶ added in v0.1.2
Make a request with an arbitrary HTTP method, i.e. not GET, POST, PUT, DELETE, etc.
func (*Response) Body ¶ added in v0.1.2
func (r *Response) Body() io.ReadCloser
The response body as a io.ReadCloser. Bear in mind that the response body can only be read once.
func (*Response) ContentLength ¶
The content length of the response body.
func (*Response) ContentType ¶
The Content-Type header for the request (if any).
func (*Response) StatusCode ¶
The status code of the response (200, 404, etc.).