Interface FetchH2HttpClientOptions

Overview

The options available for the DataAPIClient related to making HTTP requests using the fetch-h2 http client.

This, however, requires the fetch-h2 module to be installed & provided by the user, for compatibility reasons, as it is not available in all environments.

Setup

Luckily, it is only a couple of easy steps to get it working:

First, install the fetch-h2 module:

npm i fetch-h2 # or your favorite package manager's equiv.

Then, you can provide it to the client like so:

import * as fetchH2 from 'fetch-h2';
// or `const fetchH2 = require('fetch-h2');`

const client = new DataAPIClient({
httpOptions: {
client: 'fetch-h2',
fetchH2: fetchH2,
},
});

See the astra-db-ts v2.0+ README for more information on how to use fetch-h2, and the compatibility reasons for not including it by default.

Examples

For a complete example & more information, see the examples/using-http2 directory in the astra-db-ts repository

See

HttpOptions

interface FetchH2HttpClientOptions {
    client: "fetch-h2";
    fetchH2: FetchH2Like;
    http1?: FetchH2Http1Options;
    preferHttp2?: boolean;
}

Properties

client: "fetch-h2"

Tells the Data API client to use the fetch-h2 module for making HTTP requests.

See HttpOptions for the other options available.

fetchH2: FetchH2Like

The fetch-h2 module to use for making HTTP requests.

Must be provided, or an error will be thrown.

Options specific to HTTP/1.1 requests.

preferHttp2?: boolean

Whether to prefer HTTP/2 for requests to the Data API; if set to false, HTTP/1.1 will be used instead.

Note that this is only available for using the Data API; the DevOps API does not support HTTP/2.

Both versions are generally interchangeable, but HTTP/2 is recommended for better performance.

Defaults to true if never provided.

Default Value

true