rest

package
v0.0.0-...-0a6a113 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultUserAgent

func DefaultUserAgent() string

DefaultUserAgent returns a default user agent string.

Types

type Config

type Config struct {
	// UserAgent is an optional field that specifies the caller of this request.
	UserAgent string `json:"user_agent,omitempty"`

	// Set retry parameters for http client.
	RetryCount       int           `json:"retry_count,omitempty"`
	RetryWaitTime    time.Duration `json:"retry_wait_time,omitempty"`
	RetryMaxWaitTime time.Duration `json:"retry_max_wait_time,omitempty"`

	BaseURLs map[string]string `json:"base_urls,omitempty"`
}

type Interface

type Interface interface {
	Post(path string, headers, queries map[string]string, reqBody, respBody any) (*resty.Response, error)
	Put(path string, headers, queries map[string]string, reqBody, respBody any) (*resty.Response, error)
	Patch(path string, headers, queries map[string]string, reqBody, respBody any) (*resty.Response, error)
	Get(path string, headers, queries map[string]string, reqBody, respBody any) (*resty.Response, error)
	Delete(path string, headers, queries map[string]string, reqBody, respBody any) (*resty.Response, error)
}

type RESTClient

type RESTClient struct {
	*resty.Client
}

func HTTPClientFor

func HTTPClientFor(c *Config) *RESTClient

HTTPClientFor returns an http.Client that use the default transport. Will return the default http.DefaultClient if no special case behavior is needed.

func (*RESTClient) Delete

func (c *RESTClient) Delete(
	path string, headers, queries map[string]string, reqBody, respBody any) (*resty.Response, error)

Delete sends a DELETE request to the specified path with optional query parameters and request/response body, and returns the resty.Response and an error.

func (*RESTClient) Get

func (c *RESTClient) Get(
	path string, headers, queries map[string]string, reqBody, respBody any) (*resty.Response, error)

Get sends a GET request to the specified path with optional query parameters and request/response body, and returns the resty.Response and an error.

func (*RESTClient) Patch

func (c *RESTClient) Patch(
	path string, headers, queries map[string]string, reqBody, respBody any) (*resty.Response, error)

Patch sends a PATCH request to the specified path with optional query parameters and request/response body, and returns the resty.Response and an error.

func (*RESTClient) Post

func (c *RESTClient) Post(
	path string, headers, queries map[string]string, reqBody, respBody any) (*resty.Response, error)

Post sends a POST request to the specified path with optional query parameters and request/response body, and returns the resty.Response and an error.

func (*RESTClient) Put

func (c *RESTClient) Put(
	path string, headers, queries map[string]string, reqBody, respBody any) (*resty.Response, error)

Put sends a PUT request to the specified path with the given query parameters and request/response body, and returns the resty.Response and an error.

Jump to

Keyboard shortcuts

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