rest_client

package
v0.0.0-...-5d4f8f2 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsConnectionReset

func IsConnectionReset(err error) bool

Returns if the given err is "connection reset by peer" error.

Types

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type Interface

type Interface interface {
	VerbSp(verb string, subPath string) *Request
	Verb(verb string) *Request
	Post() *Request
	Put() *Request
	Get() *Request
	Delete() *Request
}

type RESTClient

type RESTClient struct {

	//TODO: add content config for server communication
	//TODO: add a backoff manager
	//TODO: add throttle
	Client *http.Client
	// contains filtered or unexported fields
}

func NewRESTClient

func NewRESTClient(baseURL *url.URL, apiPath string, client *http.Client) (*RESTClient, error)

TODO: add max qps, max burst for throttle, rate limiter etc

func (*RESTClient) APIVersion

func (c *RESTClient) APIVersion() string

func (*RESTClient) Delete

func (c *RESTClient) Delete() *Request

func (*RESTClient) Get

func (c *RESTClient) Get() *Request

func (*RESTClient) Patch

func (c *RESTClient) Patch() *Request

func (*RESTClient) Post

func (c *RESTClient) Post() *Request

func (*RESTClient) Put

func (c *RESTClient) Put() *Request

func (*RESTClient) Verb

func (c *RESTClient) Verb(verb string) *Request

func (*RESTClient) VerbSp

func (c *RESTClient) VerbSp(verb string, subPath string) *Request

verb with subpath

type Request

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

func NewRequest

func NewRequest(client HTTPClient, verb string, baseURL *url.URL, apiPath string, subPath string, timeout time.Duration) *Request

ToDO: result into TODO: add config param

func (*Request) Context

func (r *Request) Context(ctx context.Context) *Request

func (*Request) Do

func (r *Request) Do() Result

func (*Request) DoRaw

func (r *Request) DoRaw() ([]byte, error)

Raw non-JSON outcome

func (*Request) Param

func (r *Request) Param(paramName, s string) *Request

Param creates a query parameter with the given string value.

func (*Request) PrintParams

func (r *Request) PrintParams() error

func (*Request) ReadResponse

func (r *Request) ReadResponse() (io.ReadCloser, error)

read raw output from server

func (*Request) SetBodyReader

func (r *Request) SetBodyReader(t io.Reader) *Request

func (*Request) SetHeader

func (r *Request) SetHeader(key string, values ...string) *Request

func (*Request) URL

func (r *Request) URL() *url.URL

type Result

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

func NewResult

func NewResult(body []byte, contentType string, err error, statusCode int) Result

func (Result) Body

func (r Result) Body() []byte

func (Result) Error

func (r Result) Error() error

func (Result) JsonBody

func (r Result) JsonBody() (json_body map[string]interface{}, err error)

func (Result) Raw

func (r Result) Raw() ([]byte, error)

func (Result) StatusCode

func (r Result) StatusCode(statusCode *int) Result

Jump to

Keyboard shortcuts

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