sendFormRequest method
Sends a form-encoded HTTP request to the specified API endpoint.
This method supports multiple HTTP methods, including GET, POST, PUT, DELETE, and PATCH.
It sends data as application/x-www-form-urlencoded
and automatically handles response parsing.
Parameters:
endPoint
: The API endpoint URL to send the request to.param
: A map containing key-value pairs to be included in the request body.headers
: A map of HTTP headers to include in the request.method
: The HTTP method to use (default isPOST
).
Returns:
- A
Future<dynamic>
that resolves to either aMap<String, dynamic>
(JSON object),List<dynamic>
(JSON array), or an error response.
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 or array
Error Handling:
- If the response is not a valid JSON object or array, it returns an error object.
- Server errors (500+) are logged using
IDSHelper.debug
.
Implementation
Future<dynamic> sendFormRequest({
required String endPoint,
required Map<String, dynamic> param,
required Map<String, dynamic> headers,
IDSMethodType method = IDSMethodType.post,
}) async =>
_apiManagerImpl.sendFormRequest(
endPoint: endPoint,
param: param,
headers: headers,
method: method,
);