sendRequest method

Future sendRequest({
  1. required String endPoint,
  2. required Map<String, dynamic> param,
  3. required Map<String, dynamic> headers,
  4. IDSMethodType method = IDSMethodType.post,
})

Sends an HTTP request to the specified API endpoint.

This method supports multiple HTTP methods: GET, POST, PUT, PATCH, DELETE.

  • GET, DELETE: Sends data as query parameters in the URL.
  • POST, PUT, PATCH: Sends data as a raw JSON payload in the request body.

Parameters:

  • endPoint: The API endpoint URL.
  • param: A map containing request parameters (query params for GET/DELETE, JSON body for POST/PUT/PATCH).
  • headers: A map of HTTP headers to include in the request.
  • method: The HTTP method to use (default: POST).

Returns:

  • A Future<dynamic> resolving to the parsed response, which can be:
    • A Map<String, dynamic> (JSON object).
    • A List<dynamic> (JSON array).
    • A raw string if the response is not valid JSON.

Example Usage:

final response = await sendRequest(
  endPoint: "https://api.example.com/users",
  param: {"name": "John", "email": "john@example.com"},
  headers: {"Authorization": "Bearer token"},
  method: IDSMethodType.post,
);
print(response); // JSON response

Implementation

Future<dynamic> sendRequest({
  required String endPoint,
  required Map<String, dynamic> param,
  required Map<String, dynamic> headers,
  IDSMethodType method = IDSMethodType.post,
}) async =>
    _apiManagerImpl.sendRequest(
      endPoint: endPoint,
      param: param,
      headers: headers,
      method: method,
    );