postRaw<T> method
Future<(int?, String?, T)>
postRaw<T>(
- String endpoint, {
- required dynamic data,
- required T fromJson(
- 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());
}
}