sendFormRequest abstract method
Sends an HTTP request with form-encoded data.
This method sends application/x-www-form-urlencoded
form data to the specified
API endpoint and supports different HTTP methods (e.g., POST, PUT).
Parameters:
endPoint
(String): The API endpoint URL where the request should be sent.param
{'name': 'Test', 'description': 'File upload'}: A map containing key-value pairs of form data.headers
{"Authorization": "Bearer token"}: A map of headers to include in the request.method
(IDSMethodType): The HTTP method to use (e.g., POST, PUT).
Returns:
- A
Future<dynamic>
containing the server response, which could be either:- A
Map<String, dynamic>
(JSON object) - A
List<dynamic>
(JSON array)
- A
Example Usage:
final response = await sendFormRequest(
endPoint: "https://api.example.com/users",
param: {"role": "admin"},
headers: {"Authorization": "Bearer token"},
method: IDSMethodType.POST,
);
if (response is Map<String, dynamic>) {
print("Received JSON Object: ${response['data']}");
} else if (response is List<dynamic>) {
print("Received JSON Array: ${response.length} items");
}
Implementation
Future<dynamic> sendFormRequest({
required String endPoint,
required Map<String, dynamic> param,
required Map<String, dynamic> headers,
IDSMethodType method = IDSMethodType.post,
});