Function APIUrlGenerator

  • Generates a complete API URL with query parameters.

    This function constructs a full API URL by combining a base URL with a route and optional query parameters. It handles environment-specific base URLs and automatically formats query parameters into the URL.

    Parameters

    • route: string

      The API route path (e.g., '/users', '/products/123').

    • Optionalqry: { [key: string]: any }

      Optional query parameters object to append to the URL.

    • OptionalbaseUrl: string

      Optional custom base URL. If not provided, uses environment-specific URL.

    Returns string

    The complete API URL with query parameters.

    const url = APIUrlGenerator('/users', { page: 1, limit: 10 });
    console.log(url); // "https://api.example.com/users?page=1&limit=10"
    const url = APIUrlGenerator('/products', { category: 'electronics' }, 'https://custom-api.com');
    console.log(url); // "https://custom-api.com/products?category=electronics"