restclient

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidClientOptions   = errors.New("invalid client options")
	ErrUnexpectedResponseCode = errors.New("unexpected http response code")
	ErrHTTPRequest            = errors.New("http request failed")
)

Functions

This section is empty.

Types

type ClientOptions

type ClientOptions struct {
	Endpoint               string
	Insecure               bool
	Username               string
	Password               string
	Headers                map[string]string
	UseCookies             bool
	Timeout                int64
	IDAttribute            string
	CreateMethod           string
	ReadMethod             string
	UpdateMethod           string
	DestroyMethod          string
	CopyKeys               []string
	ResponseFilter         *ResponseFilter
	DriftDetection         bool
	WriteReturnsObject     bool
	CreateReturnsObject    bool
	XSSIPrefix             string
	RateLimit              float64
	TestPath               string
	OAuthClientCredentials *OAuthCredentials
	CertString             string
	KeyString              string
	CertFile               string
	KeyFile                string
}

type OAuthCredentials

type OAuthCredentials struct {
	ClientID       string
	ClientSecret   string
	TokenEndpoint  string
	EndpointParams url.Values
	Scopes         []string
}

type ResponseFilter

type ResponseFilter struct {
	Keys    []string
	Include bool
}

type RestClient

type RestClient struct {
	HTTPClient *http.Client
	Options    *ClientOptions
	// contains filtered or unexported fields
}

RestClient is a HTTP client with additional controlling fields.

func New

func New(ctx context.Context, opts *ClientOptions) (*RestClient, error)

New creates a new RestClient instance. It takes a context and ClientOptions, and returns a RestClient instance and error. It initializes the RestClient with the provided options, creating the HTTP client, OAuth client if configured, rate limiter, etc. It returns any errors encountered while initializing the client.

func (*RestClient) SendRequest

func (rc *RestClient) SendRequest(ctx context.Context, method, path, data string) (string, int, error)

SendRequest sends an HTTP request to the configured API endpoint. It handles constructing the request, adding headers and authentication, rate limiting, logging, and error handling.

func (*RestClient) ToString

func (rc *RestClient) ToString() string

ToString returns a string representation of the RestClient options.

Jump to

Keyboard shortcuts

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