A utility class for constructing and preparing API requests.

Constructors

Methods

  • Extracts the value of a specific query parameter from a given URL.

    Parameters

    • name: string

      The name of the parameter to retrieve.

    • url: string

      The URL string to parse for the parameter.

    Returns null | string

    The value of the parameter if found, otherwise null.

    const url = "https://www.supremacy1914.com/index.php?action=log&hash=yes&outputFormat=json&L=0";
    const value = RequestBuilder.getParameterByName("outputFormat", url);
    console.log(value); // Outputs: "0"
  • Prepares an API request by encoding data, generating hashes, and constructing the request URL and payload.

    Parameters

    • action: string

      The API action or endpoint being invoked.

    • data: Record<string, any>

      The payload to be sent with the request as key-value pairs.

    • config: Record<string, any>

      Configuration object containing keys, user information, and other API settings.

      • config.webapi.key - The API key.
      • config.webapi.version - The API version.
      • config.uber.authTstamp - The authentication timestamp.
      • config.uber.authHash - The authentication hash.
      • config.userId - The ID of the authenticated user.
      • config.trackingSource - The source of the tracking data.
      • config.websiteURL - The base URL for the API.
      • Amongst many others.

    Returns { postData: string; type: string; url: string }

    An object containing:

    • url: The constructed request URL.
    • postData: The encoded payload to send with the request.
    • type: The HTTP method to use (always "POST").
    const action = "getUserDetails";
    const data = { userID: 12345 };
    const config = {
    webapi: { key: "apiKey", version: "1.0" },
    uber: { authTstamp: "1276123139", authHash: "secureHash" },
    userId: "user123",
    trackingSource: "web",
    websiteURL: "https://supremacy1914.com/",
    };

    const requestDetails = RequestBuilder.prepare(action, data, config);
    console.log(requestDetails);
    // Outputs:
    // {
    // url: "https://supremacy1914.com/index.php?eID=api&key=apiKey&action=getUserDetails&hash=...",
    // postData: "data=...",
    // type: "POST",
    // }