rest

package
v1.5.19 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2021 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPClient

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

HTTPClient is an interface for testing a request object.

type Request

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

Request allows for building up a request to a server in a chained fashion. Any errors are stored until the end of your call, so you only have to check once.

func NewRequest

func NewRequest(client HTTPClient, verb string, baseURL *url.URL, versionedAPIPath string, content ContentConfig, serializers Serializers, backoff BackoffManager, throttle flowcontrol.RateLimiter) *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. If obj is a string, try to read a file of that name. If obj is a []byte, send it directly. If obj is an io.Reader, use it directly. If obj is a runtime.Object, marshal it correctly, and set Content-Type header. If obj is a runtime.Object and nil, do nothing. Otherwise, set an error.

func (*Request) Do

func (r *Request) Do() Result

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

Error type:

  • If the request can't be constructed, or an error happened earlier while building its arguments: *RequestConstructionError
  • 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() ([]byte, error)

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

func (*Request) FieldsSelectorParam

func (r *Request) FieldsSelectorParam(s fields.Selector) *Request

FieldsSelectorParam adds the given selector as a query parameter with the name paramName.

func (*Request) LabelsSelectorParam

func (r *Request) LabelsSelectorParam(s labels.Selector) *Request

LabelsSelectorParam adds the given selector as a query parameter

func (*Request) Name

func (r *Request) Name(resourceName string) *Request

Name sets the name of a resource to access (<resource>/[ns/<namespace>/]<name>)

func (*Request) Namespace

func (r *Request) Namespace(namespace string) *Request

Namespace applies the namespace scope to a request (<resource>/[ns/<namespace>/]<name>)

func (*Request) NamespaceIfScoped

func (r *Request) NamespaceIfScoped(namespace string, scoped bool) *Request

NamespaceIfScoped is a convenience function to set a namespace if scoped is true

func (*Request) Param

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

Param creates a query parameter with the given string value.

func (*Request) Prefix

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

Prefix adds segments to the relative beginning to the request path. These items will be placed before the optional Namespace, Resource, or Name sections. Setting AbsPath will clear any previously set Prefix segments

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. Some parameters (those in specialParameters) cannot be overwritten.

func (*Request) Resource

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

Resource sets the resource to access (<resource>/[ns/<namespace>/]<name>)

func (*Request) SetHeader

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

func (*Request) Stream

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

Stream formats and executes the request, and offers streaming of the response. Returns io.ReadCloser which could be used for streaming of the response, or an error Any non-2xx http status code causes an error. If we get a non-2xx code, we try to convert the body into an APIStatus object. If we can, we return that as an error. Otherwise, we create an error that lists the http status and the content of the response.

func (*Request) SubResource

func (r *Request) SubResource(subresources ...string) *Request

SubResource sets a sub-resource path which can be multiple segments segment after the resource name but before the suffix.

func (*Request) Suffix

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

Suffix appends segments to the end of the path. These items will be placed after the prefix and optional Namespace, Resource, or Name sections.

func (*Request) Timeout

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

Timeout makes the request use the given duration as a timeout. Sets the "timeout" parameter.

func (*Request) URL

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

URL returns the current working URL.

func (*Request) UintParam

func (r *Request) UintParam(paramName string, u uint64) *Request

UintParam creates a query parameter with the given value.

func (*Request) VersionedParams

func (r *Request) VersionedParams(obj runtime.Object, codec runtime.ParameterCodec) *Request

VersionedParams will take the provided object, serialize it to a map[string][]string using the implicit RESTClient API version and the default parameter codec, and then add those as parameters to the request. Use this to provide versioned query parameters from client libraries.

func (*Request) Watch

func (r *Request) Watch() (watch.Interface, error)

Watch attempts to begin watching the requested location. Returns a watch.Interface, or an error.

type RequestConstructionError

type RequestConstructionError struct {
	Err error
}

RequestConstructionError is returned when there's an error assembling a request.

func (*RequestConstructionError) Error

func (r *RequestConstructionError) Error() string

Error returns a textual description of 'r'.

type ResponseWrapper

type ResponseWrapper interface {
	DoRaw() ([]byte, error)
	Stream() (io.ReadCloser, error)
}

ResponseWrapper is an interface for getting a response. The response may be either accessed as a raw data (the whole output is put into memory) or as a stream.

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. See the Request.Do() comment for what errors you might get.

func (Result) Get

func (r Result) Get() (runtime.Object, error)

Get returns the result as an object.

func (Result) Into

func (r Result) Into(obj runtime.Object) error

Into stores the result into obj, if possible. If obj is nil it is ignored.

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.)

func (Result) WasCreated

func (r Result) WasCreated(wasCreated *bool) Result

WasCreated updates the provided bool pointer to whether the server returned 201 created or a different response.

Jump to

Keyboard shortcuts

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