post method
Make POST request with JSON body
Implementation
Future<http.Response> post(
String endpoint, {
Map<String, dynamic>? body,
Map<String, String>? headers,
}) async {
try {
final uri = Uri.parse('${_config.baseUrl}$endpoint');
if (_config.enableLogging) {
debugPrint('[ApexKYC] POST $uri');
if (body != null) {
debugPrint('[ApexKYC] Body: $body');
}
}
final response = await _client
.post(
uri,
headers: _getHeaders(additionalHeaders: headers),
body: body != null ? jsonEncode(body) : null,
)
.timeout(Duration(seconds: _config.timeoutSeconds));
if (_config.enableLogging) {
debugPrint(
'[ApexKYC] Response: ${response.statusCode} ${response.body}',
);
}
return _handleResponse(response);
} catch (e) {
if (e is ApexKycException) {
rethrow;
}
throw ApexKycException(
'Unexpected error: ${e.toString()}',
originalError: e,
);
}
}