Use Custom HTTP Clients
Speakeasy-managed SDKs will by default use an Axios HTTP Client instance created at runtime. However you may want to use a custom HTTP Client in order to use a proxy, enable custom telemetry, or use pre-configured global headers or additional configuration.
This can be done by providing a custom client when the SDK is initialized.
See below for per language examples:
The Go SDK will accept a client that provides the same interface as the standard library's http.Client
// Your custom HTTP Client
c := &http.Client{}
opts := []sdk.SDKOption{
sdk.WithClient(c),
}
s := sdk.New(opts)
The Python SDK will accept a client from the requests
package: https://requests.readthedocs.io/en/latest/
s = sdk.SDK()
# Your custom HTTP Client
client = requests.Session()
s.config_client(client)
The Typescript SDK will accept a client from the axios
package: https://axios-http.com/docs/intro
// Your custom HTTP Client
const client = axios.create();
const opts = [WithClient(client)];
const s = new SDK(opts);
The Java SDK will accept a client that implements the HTTPClient
interface in the utils
package. This will wrap a java.net.http.HttpClient
instance and the call to send
.
// Your custom HTTP Client
YouHttpClient client = new YourHttpClient();
SDK.Builder builder = SDK.builder();
builder.setClient(client);
SDK sdk = builder.build();