Documentation
¶
Index ¶
- Constants
- Variables
- func Connect(url string, opts ...*options.Option) (response.Response, error)
- func Custom(method string, url string, payload any, opts ...*options.Option) (response.Response, error)
- func Delete(url string, opts ...*options.Option) (response.Response, error)
- func Get(url string, opts ...*options.Option) (response.Response, error)
- func Head(url string, opts ...*options.Option) (response.Response, error)
- func MultipartUpload(method, url string, payload map[string]any, opts ...*options.Option) (response.Response, error)
- func Options(url string, opts ...*options.Option) (response.Response, error)
- func Patch(url string, payload any, opts ...*options.Option) (response.Response, error)
- func PatchFile(url string, filename string, opts ...*options.Option) (response.Response, error)
- func PatchFormData(url string, payload map[string]string, opts ...*options.Option) (response.Response, error)
- func PatchMultipartUpload(url string, payload map[string]interface{}, opts ...*options.Option) (response.Response, error)
- func Post(url string, payload any, opts ...*options.Option) (response.Response, error)
- func PostFile(url string, filename string, opts ...*options.Option) (response.Response, error)
- func PostFormData(url string, payload map[string]string, opts ...*options.Option) (response.Response, error)
- func PostMultipartUpload(url string, payload map[string]interface{}, opts ...*options.Option) (response.Response, error)
- func Put(url string, payload any, opts ...*options.Option) (response.Response, error)
- func PutFile(url string, filename string, opts ...*options.Option) (response.Response, error)
- func PutFormData(url string, payload map[string]string, opts ...*options.Option) (response.Response, error)
- func PutMultipartUpload(url string, payload map[string]interface{}, opts ...*options.Option) (response.Response, error)
- func Trace(url string, opts ...*options.Option) (response.Response, error)
- type Client
- func (c *Client) AddGlobalOptions(opts *options.Option)
- func (c *Client) Clear()
- func (c *Client) CloneGlobalOptions() *options.Option
- func (c *Client) Connect(url string, opts ...*options.Option) (response.Response, error)
- func (c *Client) Custom(method string, url string, payload any, opts ...*options.Option) (response.Response, error)
- func (c *Client) Delete(url string, opts ...*options.Option) (response.Response, error)
- func (c *Client) Get(url string, opts ...*options.Option) (response.Response, error)
- func (c *Client) GetGlobalOptions() *options.Option
- func (c *Client) Head(url string, opts ...*options.Option) (response.Response, error)
- func (c *Client) Options(url string, opts ...*options.Option) (response.Response, error)
- func (c *Client) Patch(url string, payload any, opts ...*options.Option) (response.Response, error)
- func (c *Client) PatchFile(url string, filename string, opts ...*options.Option) (response.Response, error)
- func (c *Client) PatchFormData(url string, payload map[string]string, opts ...*options.Option) (response.Response, error)
- func (c *Client) Post(url string, payload any, opts ...*options.Option) (response.Response, error)
- func (c *Client) PostFile(url string, filename string, opts ...*options.Option) (response.Response, error)
- func (c *Client) PostFormData(url string, payload map[string]string, opts ...*options.Option) (response.Response, error)
- func (c *Client) Put(url string, payload any, opts ...*options.Option) (response.Response, error)
- func (c *Client) PutFile(url string, filename string, opts ...*options.Option) (response.Response, error)
- func (c *Client) PutFormData(url string, payload map[string]string, opts ...*options.Option) (response.Response, error)
- func (c *Client) Responses() []response.Response
- func (c *Client) SetMaxResponses(max int)
- func (c *Client) Trace(url string, opts ...*options.Option) (response.Response, error)
- func (c *Client) UpdateGlobalOptions(opts *options.Option)
Constants ¶
const ( SchemeHTTP string = "http://" SchemeHTTPS string = "https://" SchemeWS string = "ws://" SchemeWSS string = "wss://" ContentType string = "Content-Type" ContentEncoding string = "Content-Encoding" URLencoded string = "application/x-www-form-urlencoded" )
const DefaultMaxResponses = 100
DefaultMaxResponses is the default number of responses to keep in the ring buffer.
Variables ¶
var ( ErrMaxRedirectsExceeded = errors.New("max redirects exceeded") ErrRedirectLocationMissing = errors.New("redirect location header missing") ErrPayloadNotRewindable = errors.New("cannot preserve payload on redirect") )
Sentinel errors for redirect handling.
Functions ¶
func Connect ¶
Connect performs an HTTP CONNECT to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func Custom ¶
func Custom(method string, url string, payload any, opts ...*options.Option) (response.Response, error)
Custom performs a custom HTTP method to the specified URL with the given payload. It accepts the HTTP method as its first argument, the URL string as the second argument, the payload as the third argument, and optionally additional Options to customize the request. Returns the HTTP response and an error if any.
func Delete ¶
Delete performs an HTTP DELETE to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
Note: Per HTTP semantics, DELETE requests traditionally do not include a body. If you need to send a DELETE request with a body (some APIs like Elasticsearch require this), use the Custom function instead:
client.Custom(http.MethodDelete, url, payload, opts...)
func Get ¶
Get performs an HTTP GET to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func Head ¶
Head performs an HTTP HEAD to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func MultipartUpload ¶
func MultipartUpload(method, url string, payload map[string]any, opts ...*options.Option) (response.Response, error)
MultipartUpload performs a multipart form-data upload request to the specified URL. It supports file uploads and other form fields. Data is streamed directly to the network without buffering the entire payload in memory.
func Options ¶
Options performs an HTTP OPTIONS to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func Patch ¶
Patch performs an HTTP PATCH to the specified URL with the given payload. It accepts the URL string as its first argument and the payload as the second argument. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func PatchFile ¶
PatchFile uploads a file to the specified URL using an HTTP PATCH request. It accepts the URL string as its first argument and the filename as the second argument. The file is read from the specified filename and uploaded as the request payload. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func PatchFormData ¶
func PatchFormData(url string, payload map[string]string, opts ...*options.Option) (response.Response, error)
PatchFormData performs an HTTP PATCH as an x-www-form-urlencoded payload to the specified URL. It accepts the URL string as its first argument and a map[string]string the payload. The map is converted to a url.QueryEscaped k/v pair that is sent to the server. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func PatchMultipartUpload ¶
func PatchMultipartUpload(url string, payload map[string]interface{}, opts ...*options.Option) (response.Response, error)
PatchMultipartUpload performs a PATCH multipart form-data upload request to the specified URL. This method can be used for partial updates to a resource, which might include updating or adding new file attachments.
func Post ¶
Post performs an HTTP POST to the specified URL with the given payload. It accepts the URL string as its first argument and the payload as the second argument. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func PostFile ¶
PostFile uploads a file to the specified URL using an HTTP POST request. It accepts the URL string as its first argument and the filename as the second argument. The file is read from the specified filename and uploaded as the request payload. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func PostFormData ¶
func PostFormData(url string, payload map[string]string, opts ...*options.Option) (response.Response, error)
PostFormData performs an HTTP POST as an x-www-form-urlencoded payload to the specified URL. It accepts the URL string as its first argument and a map[string]string the payload. The map is converted to a url.QueryEscaped k/v pair that is sent to the server. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func PostMultipartUpload ¶
func PostMultipartUpload(url string, payload map[string]interface{}, opts ...*options.Option) (response.Response, error)
PostMultipartUpload performs a POST multipart form-data upload request to the specified URL. This is the most common method for file uploads and creating new resources with file attachments.
func Put ¶
Put performs an HTTP PUT to the specified URL with the given payload. It accepts the URL string as its first argument and the payload as the second argument. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func PutFile ¶
PutFile uploads a file to the specified URL using an HTTP PUT request. It accepts the URL string as its first argument and the filename as the second argument. The file is read from the specified filename and uploaded as the request payload. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func PutFormData ¶
func PutFormData(url string, payload map[string]string, opts ...*options.Option) (response.Response, error)
PutFormData performs an HTTP PUT as an x-www-form-urlencoded payload to the specified URL. It accepts the URL string as its first argument and a map[string]string the payload. The map is converted to a url.QueryEscaped k/v pair that is sent to the server. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func PutMultipartUpload ¶
func PutMultipartUpload(url string, payload map[string]interface{}, opts ...*options.Option) (response.Response, error)
PutMultipartUpload performs a PUT multipart form-data upload request to the specified URL. This method is less common but can be used when updating an entire resource with new data, including file attachments.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a reusable HTTP client with persistent connection pooling. All requests made through a Client instance share the same underlying http.Client, enabling connection reuse and improved performance for multiple requests to the same hosts.
func New ¶
New returns a reusable Client with a persistent http.Client for connection pooling. Global options can be provided which will be applied to all subsequent requests.
func NewCustom ¶
NewCustom returns a reusable Client with a custom http.Client for connection pooling. Use this when you need specific http.Client configurations such as custom timeouts, transport settings, or TLS configuration. The provided client will be shared across all requests made through this Client instance.
func (*Client) AddGlobalOptions ¶
AddGlobalOptions adds the provided options to the client's global options
func (*Client) Clear ¶
func (c *Client) Clear()
Clear clears any Responses that have already been made and kept.
func (*Client) CloneGlobalOptions ¶
CloneGlobalOptions clones the global RequestOptions of the client. All configuration is copied so that global options apply to every request unless overridden per-request.
func (*Client) Connect ¶
Connect performs an HTTP CONNECT to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func (*Client) Custom ¶
func (c *Client) Custom(method string, url string, payload any, opts ...*options.Option) (response.Response, error)
Custom performs a custom HTTP method to the specified URL with the given payload. It accepts the HTTP method as its first argument, the URL string as the second argument, the payload as the third argument, and optionally additional Options to customize the request. Returns the HTTP response and an error if any.
func (*Client) Delete ¶
Delete performs an HTTP DELETE to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
Note: Per HTTP semantics, DELETE requests traditionally do not include a body. If you need to send a DELETE request with a body (some APIs like Elasticsearch require this), use the Custom method instead:
client.Custom(http.MethodDelete, url, payload, opts...)
func (*Client) Get ¶
Get performs an HTTP GET to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func (*Client) GetGlobalOptions ¶
GetGlobalOptions returns the global RequestOptions of the client.
func (*Client) Head ¶
Head performs an HTTP HEAD to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func (*Client) Options ¶
Options performs an HTTP OPTIONS to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func (*Client) Patch ¶
Patch performs an HTTP PATCH to the specified URL with the given payload. It accepts the URL string as its first argument and the payload as the second argument. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func (*Client) PatchFile ¶
func (c *Client) PatchFile(url string, filename string, opts ...*options.Option) (response.Response, error)
PatchFile uploads a file to the specified URL using an HTTP PATCH request. It accepts the URL string as its first argument and the filename as the second argument. The file is read from the specified filename and uploaded as the request payload. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func (*Client) PatchFormData ¶
func (c *Client) PatchFormData(url string, payload map[string]string, opts ...*options.Option) (response.Response, error)
PatchFormData performs an HTTP PATCH as an x-www-form-urlencoded payload to the specified URL. It accepts the URL string as its first argument and a map[string]string the payload. The map is converted to a url.QueryEscaped k/v pair that is sent to the server. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func (*Client) Post ¶
Post performs an HTTP POST to the specified URL with the given payload. It accepts the URL string as its first argument and the payload as the second argument. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func (*Client) PostFile ¶
func (c *Client) PostFile(url string, filename string, opts ...*options.Option) (response.Response, error)
PostFile uploads a file to the specified URL using an HTTP POST request. It accepts the URL string as its first argument and the filename as the second argument. The file is read from the specified filename and uploaded as the request payload. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func (*Client) PostFormData ¶
func (c *Client) PostFormData(url string, payload map[string]string, opts ...*options.Option) (response.Response, error)
PostFormData performs an HTTP POST as an x-www-form-urlencoded payload to the specified URL. It accepts the URL string as its first argument and a map[string]string the payload. The map is converted to a url.QueryEscaped k/v pair that is sent to the server. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func (*Client) Put ¶
Put performs an HTTP PUT to the specified URL with the given payload. It accepts the URL string as its first argument and the payload as the second argument. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func (*Client) PutFile ¶
func (c *Client) PutFile(url string, filename string, opts ...*options.Option) (response.Response, error)
PutFile uploads a file to the specified URL using an HTTP PUT request. It accepts the URL string as its first argument and the filename as the second argument. The file is read from the specified filename and uploaded as the request payload. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func (*Client) PutFormData ¶
func (c *Client) PutFormData(url string, payload map[string]string, opts ...*options.Option) (response.Response, error)
PutFormData performs an HTTP PUT as an x-www-form-urlencoded payload to the specified URL. It accepts the URL string as its first argument and a map[string]string the payload. The map is converted to a url.QueryEscaped k/v pair that is sent to the server. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func (*Client) Responses ¶
Responses returns a slice of responses made by this Client. Responses are returned in order from oldest to newest.
func (*Client) SetMaxResponses ¶ added in v2.2.0
SetMaxResponses sets the maximum number of responses to keep in the buffer. This creates a new ring buffer, discarding any existing responses.
func (*Client) Trace ¶
Trace performs an HTTP TRACE to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional Options to customize the request. Returns the HTTP response and an error if any.
func (*Client) UpdateGlobalOptions ¶
UpdateGlobalOptions updates the global RequestOptions of the client.