vapor-chamber API reference - v1.3.0
    Preparing search index...

    Type Alias HttpBridgeOptions

    type HttpBridgeOptions = {
        endpoint: string;
        csrf?: boolean | "inertia";
        csrfCookieUrl?: string;
        headers?: Record<string, string>;
        timeout?: number;
        retry?: number;
        noRetry?: string[];
        signal?: AbortSignal;
        onSessionExpired?: (status: number) => void;
        onRedirect?: (url: string) => void;
        actions?: string[];
        scopeController?: AbortController;
        httpClient?: HttpClient;
    }
    Index

    Properties

    endpoint: string

    Backend endpoint URL (e.g. '/api/vc')

    csrf?: boolean | "inertia"

    CSRF token strategy: • false (default) — don't attach any CSRF token • true — read from DOM (meta tag, cookie, hidden input) and attach as the appropriate header. Works with any server-rendered framework that exposes a token via one of those three sources — Laravel Blade, Rails, Django, .NET MVC, custom stacks. Auto-refreshes on HTTP 419. • 'inertia' — defer token management to Inertia's Axios instance. The bridge will skip its own CSRF reading and rely on the consumer's @inertiajs/inertia axios setup to inject the token. Use this when vapor-chamber dispatches share an HTTP layer with Inertia routes.

    csrfCookieUrl?: string

    URL to fetch on a CSRF-expiry response (HTTP 419) to obtain a fresh token. The default targets the Laravel Sanctum SPA convention because it's the most common 419-issuing backend; override for other frameworks or set to '' to disable the refresh fetch. Default: '/sanctum/csrf-cookie'.

    headers?: Record<string, string>

    Additional headers merged into every request

    timeout?: number

    Request timeout in ms. Default: 10_000

    retry?: number

    Max retry attempts on 5xx / 429 / 408. Default: 0

    noRetry?: string[]

    Actions that must never be retried regardless of the retry setting. Use for payment and other non-idempotent commands to prevent double execution.

    noRetry: ['paymentCharge', 'orderPlace']
    
    signal?: AbortSignal

    External AbortSignal (e.g. tied to component lifecycle)

    onSessionExpired?: (status: number) => void

    Called when a 401 session-expired response is received. A session-expired CustomEvent is also dispatched on window.

    onRedirect?: (url: string) => void

    Called when a backend response indicates a redirect (3xx response with Location header, OR a { redirect: '/path' } field in the JSON body). Useful for handing 302s to Inertia's router so vapor-chamber dispatches can trigger page navigations:

    onRedirect: (url) => router.visit(url)

    If not set, redirects are surfaced as { ok: false, error: 'Redirect to /path' }.

    actions?: string[]

    Which actions to forward. Glob patterns supported: '', 'cart'. Default: all actions.

    scopeController?: AbortController

    Abort controller whose signal cancels all in-flight requests when the owning scope/component is disposed. In Vapor components, create an AbortController in setup and pass it here — call .abort() in onScopeDispose to cancel orphaned requests automatically.

    // In <script setup vapor>:
    const ctrl = new AbortController();
    onScopeDispose(() => ctrl.abort());
    bus.use(createHttpBridge({ endpoint: '/api/vc', scopeController: ctrl }));
    httpClient?: HttpClient

    Custom HTTP client instance for advanced use cases (interceptors, custom baseURL, etc). When provided, the bridge uses client.post() instead of the built-in postCommand().

    const http = createHttpClient({ baseURL: '/api' });
    http.interceptors.request.use((c) => { c.headers = { ...c.headers, 'X-Tenant': '42' }; return c; });
    bus.use(createHttpBridge({ endpoint: '/vc', httpClient: http }));