callMethodType: {
    data?: any;
    httpMethod: string;
    method: string;
    params?: any;
}

Makes a general API call to a specified method with optional parameters and data.

This function performs an asynchronous request to the server using a specified HTTP method. The method and endpoint are defined by the method parameter, and the HTTP method (GET, POST, etc.) is specified by the httpMethod parameter. Depending on the HTTP method, either params or data is included in the request.

The parameters for the API call. This includes:

  • method: The name of the API method or endpoint to call.
  • httpMethod: The HTTP method to use for the request (e.g., 'GET', 'POST').
  • params (optional): The query parameters to include in the request. Used if httpMethod is 'GET'.
  • data (optional): The body data to include in the request. Used if httpMethod is not 'GET' (e.g., 'POST', 'PUT').

A promise that resolves to the response message from the API call. The response typically includes the result of the method call or relevant data based on the API endpoint.

// Make a GET request to fetch user data.
const response = await callMethod({
method: 'user.get',
httpMethod: 'GET',
params: { userId: '123' },
});
console.log(response); // Logs the response data for the user with ID 123
// Make a POST request to create a new user.
const response = await callMethod({
method: 'user.create',
httpMethod: 'POST',
data: { name: 'John Doe', email: 'john.doe@example.com' },
});
console.log(response); // Logs the response data for the newly created user

Throws an error if the request fails or if there is an issue with calling the specified method.