rest

package
v0.0.5-0...-ae6a204 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Verb(verb string) *Request
	Post() *Request
	Get() *Request
	Put() *Request
	Delete() *Request
}

Client is the interface of a rest client that can build requests for the different http verbs.

func NewClient

func NewClient(httpClient HTTPClient, baseURL string) Client

New Client creates a new REST Client.

type HTTPClient

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

HTTPClient is the interface of an http client that is compatible with *http.Client.

type Request

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

Request is a wrapper for preparing and sending a *http.Request. It provides funtionality for encoding arbitrary types to the wire format and back.

func NewRequest

func NewRequest(client HTTPClient, verb, baseURL string) *Request

NewRequest creates a new *Request which uses client to send out the prepared *http.Request.

func (*Request) AddHeader

func (r *Request) AddHeader(key, value string) *Request

AddHeader adds an HTTP header to the request.

func (*Request) Body

func (r *Request) Body(v interface{}) *Request

Body marshals v into the request body.

func (*Request) Do

func (r *Request) Do() Response

Do sends the request. This is a no-op if there were errors while building the request.

func (*Request) QueryParams

func (r *Request) QueryParams(params interface{}) *Request

QueryParams sets the request's query parameters.

func (*Request) Resource

func (r *Request) Resource(resource string) *Request

Resource sets the API resource which the request should be built for, e.g. 'monitors'. The resulting API resource path for this would be '/api/monitors'.

func (*Request) ResourceID

func (r *Request) ResourceID(resourceID string) *Request

ResourceID sets the API resource ID which the request should be built for, e.g. '123'. Example: if the resource was set to 'monitors', the resulting API resource path will be '/api/monitors/123'.

type Response

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

Response is a holder for the response body and errors that happened during a request.

func (Response) Err

func (r Response) Err() error

Err returns the request error if there was one.

func (Response) Into

func (r Response) Into(v interface{}) error

Into unmarshals the response body into v. The passed in value must be a pointer. It returns any error that occurred during the request. This is a no-op if there were errors before.

Jump to

Keyboard shortcuts

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