• Create a new Fej instance with configuration

    Factory function for creating isolated Fej instances with custom configuration. This is the recommended way to use Fej in v2.

    Parameters

    • Optional config: FejConfig

      Configuration for the instance

    Returns Fej

    A new Fej instance

    Example: Basic instance

    import { createFej } from 'fej';

    const api = createFej();
    const response = await api.fej('https://api.example.com/users');

    Example: With configuration

    const api = createFej({
    retry: {
    attempts: 3,
    delay: 1000,
    backoff: 'exponential',
    },
    errorTransforms: [
    async (error, ctx) => {
    console.error(`Request failed: ${ctx.request.url}`);
    return error;
    },
    ],
    });

    Example: Multiple instances

    const userApi = createFej({ retry: { attempts: 5 } });
    const paymentApi = createFej({ retry: { attempts: 10 } });
    // Each instance has independent configuration and middleware