Documentation
¶
Overview ¶
Package api provides a flexible HTTP API client with retry logic, rate limiting, and authentication support.
Index ¶
- type APIKeyAuth
- type Authenticator
- type BasicAuth
- type BearerTokenAuth
- type Client
- func (c *Client) Delete(ctx context.Context, path string) (*Response, error)
- func (c *Client) Do(ctx context.Context, req *Request) (*Response, error)
- func (c *Client) Get(ctx context.Context, path string, query url.Values) (*Response, error)
- func (c *Client) Post(ctx context.Context, path string, body interface{}) (*Response, error)
- func (c *Client) Put(ctx context.Context, path string, body interface{}) (*Response, error)
- func (c *Client) SetHeader(key, value string)
- type ClientConfig
- type Error
- type RESTClient
- func (r *RESTClient) DeleteJSON(ctx context.Context, path string, result interface{}) error
- func (r *RESTClient) GetJSON(ctx context.Context, path string, query url.Values, result interface{}) error
- func (r *RESTClient) Paginate(ctx context.Context, path string, pageSize int, ...) error
- func (r *RESTClient) PostJSON(ctx context.Context, path string, body, result interface{}) error
- func (r *RESTClient) PutJSON(ctx context.Context, path string, body, result interface{}) error
- type Request
- type Response
- type RetryConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIKeyAuth ¶
APIKeyAuth implements API key authentication
func (*APIKeyAuth) Authenticate ¶
func (a *APIKeyAuth) Authenticate(req *http.Request) error
type Authenticator ¶
type Authenticator interface {
// Authenticate adds authentication to a request
Authenticate(req *http.Request) error
// Refresh refreshes authentication credentials if needed
Refresh(ctx context.Context) error
}
Authenticator provides authentication for requests
type BearerTokenAuth ¶
type BearerTokenAuth struct {
Token string
}
BearerTokenAuth implements bearer token authentication
func (*BearerTokenAuth) Authenticate ¶
func (a *BearerTokenAuth) Authenticate(req *http.Request) error
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an HTTP API client
type ClientConfig ¶
type ClientConfig struct {
BaseURL string
Timeout time.Duration
Auth Authenticator
RateLimit int // Requests per second
RetryConfig *RetryConfig
Headers map[string]string
}
ClientConfig configures the API client
type Error ¶
type Error struct {
StatusCode int `json:"status_code"`
Message string `json:"message"`
Details string `json:"details,omitempty"`
}
Error represents an API error
type RESTClient ¶
type RESTClient struct {
// contains filtered or unexported fields
}
RESTClient provides a higher-level REST API client
func NewRESTClient ¶
func NewRESTClient(config ClientConfig) *RESTClient
NewRESTClient creates a new REST client
func (*RESTClient) DeleteJSON ¶
func (r *RESTClient) DeleteJSON(ctx context.Context, path string, result interface{}) error
DeleteJSON performs a DELETE request and decodes response
func (*RESTClient) GetJSON ¶
func (r *RESTClient) GetJSON(ctx context.Context, path string, query url.Values, result interface{}) error
GetJSON performs a GET request and decodes JSON response
func (*RESTClient) Paginate ¶
func (r *RESTClient) Paginate(ctx context.Context, path string, pageSize int, handler func(page interface{}) error) error
Paginate handles paginated API responses
type Request ¶
type Request struct {
Method string
Path string
Query url.Values
Headers map[string]string
Body interface{}
}
Request represents an API request
type RetryConfig ¶
type RetryConfig struct {
MaxRetries int
InitialWait time.Duration
MaxWait time.Duration
Multiplier float64
RetryOn []int // HTTP status codes to retry on
}
RetryConfig configures retry behavior
func DefaultRetryConfig ¶
func DefaultRetryConfig() *RetryConfig
DefaultRetryConfig returns default retry configuration