qfetch
    Preparing search index...

    Module @qfetch/middleware-base-url - v0.1.0

    @qfetch/middleware-base-url

    Fetch middleware for resolving URLs against a configured base URL.

    Resolves string request URLs against a base URL using the WHATWG URL Standard (new URL(input, base)). Relative URLs are resolved, absolute paths replace the pathname, and absolute URLs with schemes bypass the base entirely. URL and Request objects pass through unchanged.

    Intended for use with @qfetch/core.

    npm install @qfetch/middleware-base-url
    
    import { withBaseUrl } from '@qfetch/middleware-base-url';
    import { withHeaders } from '@qfetch/middleware-headers';
    import { compose } from '@qfetch/core';

    // Environment-aware API client
    const apiBaseUrl = process.env.API_URL ?? 'https://api.example.com/v1/';

    const api = compose(
    withHeaders({ 'Accept': 'application/json' }),
    withBaseUrl(apiBaseUrl),
    )(fetch);

    // Use relative paths throughout your application
    const users = await api('users').then(r => r.json());
    const user = await api('users/123').then(r => r.json());
    const posts = await api('posts?limit=10').then(r => r.json());

    For complete API reference, examples, and type definitions, see the API documentation.

    Functions

    withBaseUrl