This section is empty.


This section is empty.


This section is empty.


type Client

type Client struct {

	// Set specific behavior of the client.  If not set http.DefaultClient will be used.
	Client *http.Client
	// contains filtered or unexported fields

simple rest client , inspired by k8s client-go restClient

func NewRESTClient

func NewRESTClient(baseURL *url.URL, config ClientContentConfig, client *http.Client) (*Client, error)

NewRESTClient creates a new RESTClient. This client performs generic REST functions such as Get, Put, Post, and Delete on specified paths.

func RESTClientFor

func RESTClientFor(config *restclient.Config) (*Client, error)

RESTClientFor new simple rest client for config

func (*Client) Delete

func (c *Client) Delete() *Request

Delete begins a DELETE request. Short for c.Verb("DELETE").

func (*Client) Get

func (c *Client) Get() *Request

Get begins a GET request. Short for c.Verb("GET").

func (*Client) Post

func (c *Client) Post() *Request

Post begins a POST request. Short for c.Verb("POST").

func (*Client) Put

func (c *Client) Put() *Request

Put begins a PUT request. Short for c.Verb("PUT").

func (*Client) Verb

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

type ClientContentConfig

type ClientContentConfig struct {
	// AcceptContentTypes specifies the types the client will accept and is optional.
	// If not set, ContentType will be used to define the Accept header
	AcceptContentTypes string
	// ContentType specifies the wire format used to communicate with the server.
	// This value will be set as the Accept header on requests made to the server if
	// AcceptContentTypes is not set, and as the default content type on any object
	// sent to the server. If not set, "application/json" is used.
	ContentType string

type Interface

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

Interface rest client interface

type Request

type Request struct {
	// contains filtered or unexported fields

func NewRequest

func NewRequest(c *Client) *Request

NewRequest creates a new request helper object for accessing runtime.Objects on a server.

func (*Request) AbsPath

func (r *Request) AbsPath(segments ...string) *Request

AbsPath overwrites an existing path with the segments provided. Trailing slashes are preserved when a single segment is passed.

func (*Request) Body

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

Body makes the request use obj as the body. Optional.

func (*Request) Do

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

Do formats and executes the request. Returns a Result object for easy response processing.

Error type:

* If the server responds with a status: *errors.StatusError or *errors.UnexpectedObjectError
* http.Client.Do errors are returned directly.

func (*Request) DoRaw

func (r *Request) DoRaw(ctx context.Context) ([]byte, error)

DoRaw executes the request but does not process the response body.

func (*Request) Param

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

Param creates a query parameter with the given string value.

func (*Request) RequestURI

func (r *Request) RequestURI(uri string) *Request

RequestURI overwrites existing path and parameters with the value of the provided server relative URI.

func (*Request) SetHeader

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

func (*Request) Timeout

func (r *Request) Timeout(d time.Duration) *Request

Timeout makes the request use the given duration as an overall timeout for the request. Additionally, if set passes the value as "timeout" parameter in URL.

func (*Request) URL

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

URL returns the current working URL.

func (*Request) Verb

func (r *Request) Verb(verb string) *Request

Verb sets the verb this request will use.

type Result

type Result struct {
	// contains filtered or unexported fields

Result contains the result of calling Request.Do().

func (Result) Error

func (r Result) Error() error

Error returns the error executing the request, nil if no error occurred. If the returned object is of type Status and has Status != StatusSuccess, the additional information in Status will be used to enrich the error. See the Request.Do() comment for what errors you might get.

func (Result) Get

func (r Result) Get() (interface{}, error)

func (Result) Into

func (r Result) Into(obj interface{}) error

func (Result) Raw

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

Raw returns the raw result.

func (Result) StatusCode

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

StatusCode returns the HTTP status code of the request. (Only valid if no error was returned.)

Jump to

Keyboard shortcuts

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