post method
Makes a POST request to the specified endpoint
Implementation
Future<Map<String, dynamic>> post(
String endpoint, {
Map<String, String>? headers,
Map<String, dynamic>? body,
Map<String, String>? formData,
}) async {
final uri = _buildUri(endpoint);
final request = http.Request('POST', uri);
// Set default headers
request.headers.addAll({
'Content-Type': formData != null
? 'application/x-www-form-urlencoded'
: 'application/json',
});
if (headers != null) {
request.headers.addAll(headers);
}
// Set body
if (formData != null) {
request.bodyFields = formData;
} else if (body != null) {
request.body = jsonEncode(body);
}
return _executeRequest(request);
}