Documentation ¶
Index ¶
- type Client
- func (c *Client) Clear()
- func (c *Client) CloneGlobalOptions() RequestOptions
- func (c *Client) Connect(url string, opt ...RequestOptions) (Response, error)
- func (c *Client) Custom(method string, url string, payload []byte, opt ...RequestOptions) (Response, error)
- func (c *Client) Delete(url string, opt ...RequestOptions) (Response, error)
- func (c *Client) Get(url string, opt ...RequestOptions) (Response, error)
- func (c *Client) GetGlobalOptions() RequestOptions
- func (c *Client) Head(url string, opt ...RequestOptions) (Response, error)
- func (c *Client) Options(url string, opt ...RequestOptions) (Response, error)
- func (c *Client) Patch(url string, payload []byte, opt ...RequestOptions) (Response, error)
- func (c *Client) Post(url string, payload []byte, opt ...RequestOptions) (Response, error)
- func (c *Client) Put(url string, payload []byte, opt ...RequestOptions) (Response, error)
- func (c *Client) Trace(url string, opt ...RequestOptions) (Response, error)
- func (c *Client) UpdateGlobalOptions(options RequestOptions)
- type CompressionType
- type Header
- type RequestOptions
- func (opt *RequestOptions) AddCookie(cookie *http.Cookie)
- func (opt *RequestOptions) AddHeader(key string, value string)
- func (opt *RequestOptions) ClearCookies()
- func (opt *RequestOptions) ClearHeaders()
- func (opt *RequestOptions) Compress(compressionType CompressionType)
- func (opt *RequestOptions) ListCookies()
- func (opt *RequestOptions) ListHeaders()
- func (opt *RequestOptions) SetProtocolScheme(scheme string)
- type Response
- func Connect(url string, opt ...RequestOptions) (Response, error)
- func Custom(method string, url string, payload []byte, opt ...RequestOptions) (Response, error)
- func Delete(url string, opt ...RequestOptions) (Response, error)
- func Get(url string, opt ...RequestOptions) (Response, error)
- func Head(url string, opt ...RequestOptions) (Response, error)
- func Options(url string, opt ...RequestOptions) (Response, error)
- func Patch(url string, payload []byte, opt ...RequestOptions) (Response, error)
- func Post(url string, payload []byte, opt ...RequestOptions) (Response, error)
- func Put(url string, payload []byte, opt ...RequestOptions) (Response, error)
- func Trace(url string, opt ...RequestOptions) (Response, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an HTTP client.
func New ¶
func New(options ...RequestOptions) *Client
New returns a reusable Client. It is possible to include a global RequestOptions which will be used on all subsequent requests.
func NewCustom ¶
func NewCustom(client *http.Client, options ...RequestOptions) *Client
NewCustom returns a reusable client with a custom defined *http.Client This is useful in scenarios where you want to change any configurations for the http.Client
func (*Client) Clear ¶
func (c *Client) Clear()
Clear clears any Responses that have already been made and kept.
func (*Client) CloneGlobalOptions ¶
func (c *Client) CloneGlobalOptions() RequestOptions
CloneGlobalOptions clones the global RequestOptions of the client.
func (*Client) Connect ¶
func (c *Client) Connect(url string, opt ...RequestOptions) (Response, error)
Connect performs an HTTP CONNECT request to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional RequestOptions 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 []byte, opt ...RequestOptions) (Response, error)
Custom performs a custom HTTP request 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 RequestOptions to customize the request. Returns the HTTP response and an error if any.
func (*Client) Delete ¶
func (c *Client) Delete(url string, opt ...RequestOptions) (Response, error)
Delete performs an HTTP DELETE request to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional RequestOptions to customize the request. Returns the HTTP response and an error if any.
func (*Client) Get ¶
func (c *Client) Get(url string, opt ...RequestOptions) (Response, error)
Get performs an HTTP GET request to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional RequestOptions to customize the request. Returns the HTTP response and an error if any.
func (*Client) GetGlobalOptions ¶
func (c *Client) GetGlobalOptions() RequestOptions
GetGlobalOptions returns the global RequestOptions of the client.
func (*Client) Head ¶
func (c *Client) Head(url string, opt ...RequestOptions) (Response, error)
Head performs an HTTP HEAD request to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional RequestOptions to customize the request. Returns the HTTP response and an error if any.
func (*Client) Options ¶
func (c *Client) Options(url string, opt ...RequestOptions) (Response, error)
Options performs an HTTP OPTIONS request to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional RequestOptions to customize the request. Returns the HTTP response and an error if any.
func (*Client) Patch ¶
Patch performs an HTTP PATCH request 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 RequestOptions to customize the request. Returns the HTTP response and an error if any.
func (*Client) Post ¶
Post performs an HTTP POST request 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 RequestOptions to customize the request. Returns the HTTP response and an error if any.
func (*Client) Put ¶
Put performs an HTTP PUT request 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 RequestOptions to customize the request. Returns the HTTP response and an error if any.
func (*Client) Trace ¶
func (c *Client) Trace(url string, opt ...RequestOptions) (Response, error)
Trace performs an HTTP TRACE request to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional RequestOptions to customize the request. Returns the HTTP response and an error if any.
func (*Client) UpdateGlobalOptions ¶
func (c *Client) UpdateGlobalOptions(options RequestOptions)
UpdateGlobalOptions updates the global RequestOptions of the client.
type CompressionType ¶
type CompressionType string
const ( CompressionNone CompressionType = "" CompressionGzip CompressionType = "gzip" CompressionDeflate CompressionType = "deflate" CompressionBrotli CompressionType = "br" )
type RequestOptions ¶
type RequestOptions struct { Headers []Header // Custom headers to be added to the request. Cookies []*http.Cookie // Cookies to be included in the request. ProtocolScheme string // define a custom protocol scheme. It defaults to https Compression CompressionType UserAgent string }
RequestOptions represents additional options for the HTTP request.
func (*RequestOptions) AddCookie ¶
func (opt *RequestOptions) AddCookie(cookie *http.Cookie)
AddCookie adds a new cookie to the RequestOptions.
func (*RequestOptions) AddHeader ¶
func (opt *RequestOptions) AddHeader(key string, value string)
AddHeader adds a new header to the RequestOptions.
func (*RequestOptions) ClearCookies ¶
func (opt *RequestOptions) ClearCookies()
ClearCookies clears all cookies in the RequestOptions.
func (*RequestOptions) ClearHeaders ¶
func (opt *RequestOptions) ClearHeaders()
ClearHeaders clears all headers in the RequestOptions.
func (*RequestOptions) Compress ¶
func (opt *RequestOptions) Compress(compressionType CompressionType)
func (*RequestOptions) ListCookies ¶
func (opt *RequestOptions) ListCookies()
ListCookies prints out the list of cookies in the RequestOptions.
func (*RequestOptions) ListHeaders ¶
func (opt *RequestOptions) ListHeaders()
ListHeaders prints out the list of headers in the RequestOptions.
func (*RequestOptions) SetProtocolScheme ¶
func (opt *RequestOptions) SetProtocolScheme(scheme string)
type Response ¶
type Response struct { UUID uuid.UUID URL string // URL of the request. Method string // HTTP method of the request. RequestPayload []byte // Payload of the request. Options RequestOptions // Additional options for the request. RequestTime int64 // The time when the request was made Status string // Status of the HTTP response. StatusCode int // HTTP status code of the response. Proto string // HTTP protocol used. Header http.Header // HTTP headers of the response. ContentLength int64 TransferEncoding []string // Transfer encoding of the response CompressionType CompressionType Uncompressed bool Cookies []*http.Cookie // Cookies received in the response. AccessTime time.Duration // Time taken to complete the request. Body bytes.Buffer // Response body as bytes. Error error // Error encountered during the request. TLS *tls.ConnectionState }
Response represents the HTTP response along with additional details.
func Connect ¶
func Connect(url string, opt ...RequestOptions) (Response, error)
Connect performs an HTTP CONNECT request to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional RequestOptions to customize the request. Returns the HTTP response and an error if any.
func Custom ¶
Custom performs a custom HTTP request 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 RequestOptions to customize the request. Returns the HTTP response and an error if any.
func Delete ¶
func Delete(url string, opt ...RequestOptions) (Response, error)
Delete performs an HTTP DELETE request to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional RequestOptions to customize the request. Returns the HTTP response and an error if any.
func Get ¶
func Get(url string, opt ...RequestOptions) (Response, error)
Get performs an HTTP GET request to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional RequestOptions to customize the request. Returns the HTTP response and an error if any.
func Head ¶
func Head(url string, opt ...RequestOptions) (Response, error)
Head performs an HTTP HEAD request to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional RequestOptions to customize the request. Returns the HTTP response and an error if any.
func Options ¶
func Options(url string, opt ...RequestOptions) (Response, error)
Options performs an HTTP OPTIONS request to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional RequestOptions to customize the request. Returns the HTTP response and an error if any.
func Patch ¶
func Patch(url string, payload []byte, opt ...RequestOptions) (Response, error)
Patch performs an HTTP PATCH request 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 RequestOptions to customize the request. Returns the HTTP response and an error if any.
func Post ¶
func Post(url string, payload []byte, opt ...RequestOptions) (Response, error)
Post performs an HTTP POST request 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 RequestOptions to customize the request. Returns the HTTP response and an error if any.
func Put ¶
func Put(url string, payload []byte, opt ...RequestOptions) (Response, error)
Put performs an HTTP PUT request 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 RequestOptions to customize the request. Returns the HTTP response and an error if any.
func Trace ¶
func Trace(url string, opt ...RequestOptions) (Response, error)
Trace performs an HTTP TRACE request to the specified URL. It accepts the URL string as its first argument. Optionally, you can provide additional RequestOptions to customize the request. Returns the HTTP response and an error if any.