Back to

package rek

Latest Go to latest
Published: May 13, 2020 | License: MIT | Module:



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

func BodyAsBytes

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

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.

type Option

type Option func(*options)

func Accept

func Accept(accept string) Option

Applies an Accept header to the request.

func ApiKey

func ApiKey(key string) Option

Adds an API key to the request.

func BasicAuth

func BasicAuth(username, password string) Option

Add a basic auth username and password to the request.

func Bearer

func Bearer(bearer string) Option

Add a bearer header of the form "Authorization: Bearer ..."

func Callback

func Callback(cb func(*Response)) Option

Add a callback function for handling the Response.

func Client

func Client(client *http.Client) Option

Provide your own http.Client struct to make the request.

func Context

func Context(ctx context.Context) Option

Pass a context into the HTTP request (allows for request cancellation, for example).

func CookieJar

func CookieJar(jar http.CookieJar) Option

Add a cookie jar to the request.

func Cookies

func Cookies(cookies []*http.Cookie) Option

Add cookies to the request.

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 DisallowRedirects

func DisallowRedirects() Option

Turn redirects off.

func File

func File(fieldName, filepath string, params map[string]string) Option

Create a multipart file upload request.

func FormData

func FormData(form map[string]string) Option

Add key/value form data to the request body and apply a "Content-Type: application/x-www-form-urlencoded" header.

func Headers

func Headers(headers map[string]string) Option

Add headers to the request.

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 OAuth2

func OAuth2(cfg *oauth2.Config, tok *oauth2.Token) Option

Apply an OAuth2 configuration and token to the request.

func RequestModifier

func RequestModifier(modifier func(*http.Request)) Option

Applies a user-provided request modification function. Applied after all other request modifications have been made by the selected options.

func Timeout

func Timeout(timeout time.Duration) Option

Add a timeout to the request.

func UserAgent

func UserAgent(agent string) Option

Add a User-Agent header to the request.

type Response

type Response struct {
	// contains filtered or unexported fields

A struct containing the relevant response information returned by a rek request.

func Delete

func Delete(url string, opts ...Option) (*Response, error)

DELETE request

func Do

func Do(method, url string, opts ...Option) (*Response, error)

Make a request with an arbitrary HTTP method, i.e. not GET, POST, PUT, DELETE, etc.

func Get

func Get(url string, opts ...Option) (*Response, error)

GET request

func Head(url string, opts ...Option) (*Response, error)

HEAD request

func Patch

func Patch(url string, opts ...Option) (*Response, error)

PATCH request

func Post

func Post(url string, opts ...Option) (*Response, error)

POST request

func Put

func Put(url string, opts ...Option) (*Response, error)

PUT request

func (*Response) Body

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

func (r *Response) ContentLength() int64

The content length of the response body.

func (*Response) ContentType

func (r *Response) ContentType() string

The Content-Type header for the request (if any).

func (*Response) Cookies

func (r *Response) Cookies() []*http.Cookie

The cookies associated with the response.

func (*Response) Encoding

func (r *Response) Encoding() []string

The response's encoding.

func (*Response) Headers

func (r *Response) Headers() map[string]string

The headers associated with the response.

func (*Response) Raw

func (r *Response) Raw() *http.Response

The raw *http.Response returned by the operation.

func (*Response) Status

func (r *Response) Status() string

The response's status, e.g. "200 OK."

func (*Response) StatusCode

func (r *Response) StatusCode() int

The status code of the response (200, 404, etc.).

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
f or F : Jump to identifier