Skip to content

Start typing to search the documentation.

createBapxClient(...)

AI-generated, awaiting review View as Markdown
import { createBapxClient } from '@bapX/sdk';

const client = createBapxClient({
  baseUrl: 'https://example.com/api',
  token: process.env.FLUE_TOKEN,
});

In a browser, baseUrl may be relative to location.origin. This is the usual same-origin setup:

const client = createBapxClient({ baseUrl: '/api' });

Outside a browser, baseUrl must be absolute; a relative value throws an error.

createBapxClient(...)

function createBapxClient(options: CreateBapxClientOptions): BapxClient;

Creates a client for the public routes of a deployed Bapx application.

CreateBapxClientOptions

FieldTypeDefaultDescription
baseUrlstringURL where the public bapX() sub-app is mounted, including any pathname. Browser clients may use a relative URL.
fetchtypeof fetchglobal fetchCustom HTTP implementation. Also used for Durable Streams event streaming. Point it at a Cloudflare service binding to reach a private agent Worker.
headersRequestHeadersHeaders merged into each HTTP and stream request.
tokenstringBearer token added to HTTP and stream requests.

RequestHeaders

type RequestHeaders =
  | Record<string, string>
  | (() => Record<string, string> | Promise<Record<string, string>>);

Use a function to resolve headers separately for each HTTP request and stream reconnection.