sendFormRequest method

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

Sends an HTTP request with form-encoded data to the specified API endpoint.

This method supports GET, POST, PUT, DELETE, and PATCH HTTP methods. It sends requests using the application/x-www-form-urlencoded format and handles responses dynamically.

Supported Response Types:

  • JSON Object (Map<String, dynamic>)
  • JSON Array (List<dynamic>)
  • Raw String (if response is not a valid JSON)

Parameters:

  • endPoint: The API endpoint URL to send the request to.
  • param: A map of key-value pairs to be included in the request body (for POST, PUT, PATCH) or as query parameters (for GET).
  • headers: A map of HTTP headers to include in the request.
  • method: The HTTP method to use (GET, POST, PUT, DELETE, PATCH). Default is POST.

Returns:

  • A Future<dynamic> resolving to:
    • Map<String, dynamic> if the response is a JSON object.
    • List<dynamic> if the response is a JSON array.
    • String if the response is plain text or invalid JSON.

Example Usage:

final response = await sendFormRequest(
  endPoint: "https://api.example.com/data",
  param: {"key": "value"},
  headers: {"Authorization": "Bearer token"},
  method: IDSMethodType.post,
);
print(response); // JSON object, array, or raw string

Implementation

@override
Future<dynamic> sendFormRequest({
  required String endPoint,
  required Map<String, dynamic> param,
  required Map<String, dynamic> headers,
  IDSMethodType method = IDSMethodType.post,
}) async {
  return await _sendFormRequest(
    endPoint: endPoint,
    param: param,
    headers: headers,
    method: method,
  );
}