post method

Future<Response> post(
  1. String endpoint, {
  2. Map<String, dynamic>? body,
  3. Map<String, String>? headers,
})

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,
    );
  }
}