https

package
v0.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package https provides a unified HTTP client for making API requests with centralized auth, error handling, and debug logging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckAndClose added in v0.19.0

func CheckAndClose(resp *http.Response, err error) error

CheckAndClose closes a response whose body is not needed and rejects non-2xx statuses.

func CheckResponse added in v0.19.0

func CheckResponse(resp *http.Response) error

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

func DecodeJSON[T any](resp *http.Response, err error) (T, error)

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

func NewGenerated(transport *Client) *openapi.Client

NewGenerated connects generated REST operations to the configured SDK transport. A nil transport returns nil.

func Positive added in v0.19.0

func Positive(value int) *int

Positive represents an optional positive query limit.

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.

func String added in v0.19.0

func String(value string) *string

String represents an optional nonempty query parameter.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a unified HTTP client for API requests.

func NewClient

func NewClient(apiKey, baseURL string, log logger.Logger) *Client

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

func NewWrappedClient(apiKey, baseURL string, httpClient *http.Client, log logger.Logger) *Client

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) APIKey added in v0.1.0

func (c *Client) APIKey() string

APIKey returns the API key used by this client.

func (*Client) BaseURL added in v0.19.0

func (c *Client) BaseURL() string

BaseURL returns the configured server URL, including any deployment prefix.

func (*Client) Client added in v0.1.0

func (c *Client) Client() *http.Client

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

func (c *Client) Do(req *http.Request) (*http.Response, error)

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").

func (*Client) JSONBody added in v0.19.0

func (c *Client) JSONBody(body any) (io.Reader, error)

JSONBody serializes a request body. Do logs it when the request is sent.

func (*Client) POST

func (c *Client) POST(ctx context.Context, path string, body interface{}) (*http.Response, error)

POST makes a POST request with a JSON body. The path is appended to the base URL (e.g., "/api/apikey/login").

type HTTPError added in v0.1.0

type HTTPError struct {
	StatusCode int
	Body       string
	// contains filtered or unexported fields
}

HTTPError represents an HTTP error response with status code.

func (*HTTPError) Error added in v0.1.0

func (e *HTTPError) Error() string

func (*HTTPError) Unwrap added in v0.1.0

func (e *HTTPError) Unwrap() error

type OpenAPIClient added in v0.19.0

type OpenAPIClient struct {
	openapi.Client
	// contains filtered or unexported fields
}

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.

func (*OpenAPIClient) Do added in v0.19.0

func (c *OpenAPIClient) Do(req *http.Request) (*http.Response, error)

Do sends generated requests unchanged through the shared SDK transport.

func (*OpenAPIClient) JSONBody added in v0.19.0

func (c *OpenAPIClient) JSONBody(value any) (io.Reader, error)

JSONBody preserves public request models and arbitrary JSON without converting through generated models. Generated WithBody methods accept the encoded body.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL