Documentation
¶
Overview ¶
Package httpclient provides a reusable HTTP client for JSON-based APIs.
Index ¶
Constants ¶
View Source
const ( // OctetStream represents the MIME type for binary data. OctetStream = "application/octet-stream" // ApplicationJSON represents the MIME type for JSON data. ApplicationJSON = "application/json" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
Error struct {
Message string `json:"message"`
Type string `json:"type"`
} `json:"error"`
}
APIError represents a standard error response from the API.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client defines a reusable abstraction for JSON-based APIs.
func NewClient ¶
NewClient initializes a reusable HTTP client. When headerName is non-empty, every outgoing request carries authentication in the form of headerName: headerValue.
func (*Client) Do ¶
func (c *Client) Do(ctx context.Context, method, path string, queryParams map[string]string, payload any, out any) error
Do sends a request and decodes the JSON response into the provided 'out'. Pass a pointer as 'out' (e.g. &myStruct). If out is nil, the response body is discarded.
Click to show internal directories.
Click to hide internal directories.