Documentation
¶
Index ¶
- Variables
- type Option
- func WithBody(body io.Reader) Option
- func WithCookies(cookies ...*http.Cookie) Option
- func WithDecompressGzip() Option
- func WithForm(values map[string]string) Option
- func WithHeader(key, value string) Option
- func WithHeaders(h map[string]string) Option
- func WithJSON(v any) Option
- func WithProxy(rawURL string) Option
- func WithQuery(q map[string]string) Option
- func WithRedirect(max int) Option
- func WithTimeout(d time.Duration) Option
- type Request
- type Response
- func Delete(ctx context.Context, url string, opts ...Option) (*Response, error)
- func Get(ctx context.Context, url string, opts ...Option) (*Response, error)
- func Head(ctx context.Context, url string, opts ...Option) (*Response, error)
- func Options(ctx context.Context, url string, opts ...Option) (*Response, error)
- func Patch(ctx context.Context, url string, opts ...Option) (*Response, error)
- func Post(ctx context.Context, url string, opts ...Option) (*Response, error)
- func Put(ctx context.Context, url string, opts ...Option) (*Response, error)
- type Session
- func (s *Session) Delete(ctx context.Context, url string, opts ...Option) (*Response, error)
- func (s *Session) Get(ctx context.Context, url string, opts ...Option) (*Response, error)
- func (s *Session) Head(ctx context.Context, url string, opts ...Option) (*Response, error)
- func (s *Session) Options(ctx context.Context, url string, opts ...Option) (*Response, error)
- func (s *Session) Patch(ctx context.Context, url string, opts ...Option) (*Response, error)
- func (s *Session) Post(ctx context.Context, url string, opts ...Option) (*Response, error)
- func (s *Session) Put(ctx context.Context, url string, opts ...Option) (*Response, error)
- type StatusError
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRequest indicates a request build or configuration error. ErrRequest = fmt.Errorf("request error") // ErrNetwork indicates a transport/network error. ErrNetwork = fmt.Errorf("network error") // ErrTimeout indicates a timeout error. ErrTimeout = fmt.Errorf("timeout") // ErrStatus indicates a non-2xx HTTP status. ErrStatus = fmt.Errorf("unexpected status") // ErrResponse indicates a response read or decode error. ErrResponse = fmt.Errorf("response error") // ErrResponseNil indicates a nil response or body. ErrResponseNil = fmt.Errorf("nil response") // ErrNoContent indicates an empty response body. ErrNoContent = fmt.Errorf("empty response body") )
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Request)
Option mutates a Request.
func WithBody ¶
WithBody sets a raw body reader. Note: the reader is used as-is; do not reuse it across concurrent requests.
func WithCookies ¶
WithCookies adds cookies to the request.
func WithDecompressGzip ¶ added in v1.0.1
func WithDecompressGzip() Option
WithDecompressGzip enables gzip auto-decompression for response bodies.
func WithHeader ¶
WithHeader sets a single header value (overwrites existing).
func WithHeaders ¶
WithHeaders sets multiple headers (overwrites existing keys).
func WithRedirect ¶
WithRedirect sets max redirects. max=0 disables redirects.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request holds request state built from options.
type Response ¶
type Response struct {
Raw *http.Response
StatusCode int
Headers http.Header
// contains filtered or unexported fields
}
Response wraps http.Response with convenience helpers.
func (*Response) Bytes ¶
Bytes reads and caches the response body and returns ErrResponseNil on nil responses.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session holds default options for requests.
func NewSession ¶
NewSession creates a new session with default options.
type StatusError ¶
StatusError is returned for non-2xx responses.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
func (*StatusError) Unwrap ¶
func (e *StatusError) Unwrap() error