Documentation
¶
Overview ¶
Package https provides a unified HTTP client for making API requests with centralized auth, error handling, and debug logging.
Index ¶
- func CheckAndClose(resp *http.Response, err error) error
- func CheckResponse(resp *http.Response) error
- func DecodeJSON[T any](resp *http.Response, err error) (T, error)
- func NewGenerated(transport *Client) *openapi.Client
- func Positive(value int) *int
- func Query(name, value string) openapi.RequestEditorFn
- func String(value string) *string
- type Client
- func (c *Client) APIKey() string
- func (c *Client) BaseURL() string
- func (c *Client) Client() *http.Client
- func (c *Client) Do(req *http.Request) (*http.Response, error)
- func (c *Client) GET(ctx context.Context, path string, params map[string]string) (*http.Response, error)
- func (c *Client) JSONBody(body any) (io.Reader, error)
- func (c *Client) POST(ctx context.Context, path string, body interface{}) (*http.Response, error)
- type HTTPError
- type OpenAPIClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckAndClose ¶ added in v0.19.0
CheckAndClose closes a response whose body is not needed and rejects non-2xx statuses.
func CheckResponse ¶ added in v0.19.0
CheckResponse returns an HTTPError for non-success status codes, consuming the error body. It leaves successful bodies untouched. The caller owns Body.Close. SDK loaders also use this with plain generated clients, whose transports need not reject non-2xx responses.
func DecodeJSON ¶ added in v0.19.0
DecodeJSON closes a response, rejects non-2xx statuses, and decodes the successful body. Pass a generated operation's results directly:
rows, err := https.DecodeJSON[rowList](client.GetDataset(ctx, params))
func NewGenerated ¶ added in v0.19.0
NewGenerated connects generated REST operations to the configured SDK transport. A nil transport returns nil.
func Query ¶ added in v0.19.0
func Query(name, value string) openapi.RequestEditorFn
Query preserves a public query parameter missing from the pinned specification. Generated parameters are retained; an empty value is omitted.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a unified HTTP client for API requests.
func NewClient ¶
NewClient creates a new HTTP client with the given credentials and base URL. The baseURL parameter is the base URL (e.g., "https://api.braintrust.dev" or "https://www.braintrust.dev").
func NewWrappedClient ¶ added in v0.0.2
NewWrappedClient creates a new HTTP client with a custom http.Client. This is useful for tests that need to wrap the HTTP client (e.g., with VCR).
func (*Client) BaseURL ¶ added in v0.19.0
BaseURL returns the configured server URL, including any deployment prefix.
func (*Client) Client ¶ added in v0.1.0
Client returns the underlying http.Client. This is useful for extracting the client for auth.Session when using VCR.
func (*Client) Do ¶ added in v0.19.0
Do executes the HTTP request with auth, error checking, and logging.
func (*Client) GET ¶
func (c *Client) GET(ctx context.Context, path string, params map[string]string) (*http.Response, error)
GET makes a GET request with query parameters. The path is appended to the base URL (e.g., "/v1/project").
type OpenAPIClient ¶ added in v0.19.0
OpenAPIClient uses generated endpoints while retaining SDK authentication, errors, timeouts, logging, and the caller's configured HTTP client.
func NewOpenAPIClient ¶ added in v0.19.0
func NewOpenAPIClient(transport *Client) *OpenAPIClient
NewOpenAPIClient adapts an existing transport without changing its configuration. A nil transport stays nil so facade validation can run before any I/O.