postRaw<T> method

Future<(int?, String?, T)> postRaw<T>(
  1. String endpoint, {
  2. required dynamic data,
  3. required T fromJson(
    1. dynamic
    ),
})

Implementation

Future<(int? statusCode, String? message, T data)> postRaw<T>(
  String endpoint, {
  required dynamic data,
  required T Function(dynamic) fromJson,
}) async {
  try {
    final uri = _buildUri(endpoint, null);
    final String encodedData = jsonEncode(data);
    _logRequest('POST', uri, body: encodedData);

    final response = await _client.post(
      uri,
      headers: _getHeaders(),
      body: encodedData,
    );
    _logResponse(response);

    final statusCode = response.statusCode;
    // http library doesn't parse status message strings natively, providing standard fallback
    final message = response.statusCode == 200 ? 'OK' : 'Error';

    final decodedData = jsonDecode(response.body);
    return (statusCode, message, fromJson(decodedData));
  } catch (e) {
    throw Exception(e.toString());
  }
}