httpclient

package
v0.0.0-...-b5f7192 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetStatusString

func GetStatusString(statusCode int) string

Types

type APIResponse

type APIResponse struct {
	Payload    []byte
	StatusCode int
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient() Client

func (*Client) Delete

func (c *Client) Delete(url string, headers map[string]string, params map[string]interface{}) (*APIResponse, error)

func (Client) EnsureWithoutHeader

func (c Client) EnsureWithoutHeader(headerName string) Client

Ensure that a header is removed before requests are performed

func (Client) EnsureWithoutQueryParam

func (c Client) EnsureWithoutQueryParam(paramName string) Client

Ensure that a query parameter is removed before requests are performed

func (*Client) Get

func (c *Client) Get(url string, headers map[string]string, params map[string]interface{}) (*APIResponse, error)

Attempt at copying the behaviour of axios.get (JS) / resquests.get (Python)

func (*Client) Patch

func (c *Client) Patch(url string, headers map[string]string, params map[string]interface{}, payload []byte) (*APIResponse, error)

func (*Client) Post

func (c *Client) Post(url string, headers map[string]string, payload map[string]interface{}) (*APIResponse, error)

func (Client) WithConfig

func (c Client) WithConfig(conf *Config) Client

Returns a copy of the client with headers, params and baseURL set by the config

func (Client) WithHeader

func (c Client) WithHeader(key, value string) Client

Add a header to the list of default headers

func (Client) WithHeaders

func (c Client) WithHeaders(headers map[string]string) Client

Add headers to the list of default headers

func (Client) WithQueryParams

func (c Client) WithQueryParams(newParams map[string]interface{}) Client

Add query parameters to default query parameters

type Config

type Config struct {
	DefaultQueryParams map[string]interface{}
	DefaultHeaders     map[string]string
	BaseURL            string
}

type Request

type Request http.Request

type RequestTransform

type RequestTransform func(req *http.Request) *http.Request

RequestTransform performs some operation on the http request Transforms can be used to e.g. strip the request of a single header or query param allowing for easy testing of responses due to missing params

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL