readOne<T> method
Reads the response body as JSON and applies the fromMap function to create an object.
Example:
final data = await client.get('https://example.com').readOne((json) => MyObject.fromMap(json));
Implementation
Future<T> readOne<T>(T Function(Map<String, dynamic>) fromMap) async {
final response = await go();
if (response.statusCode == HttpStatus.ok) {
final jsonData = await response.transform(utf8.decoder).join();
return fromMap(jsonDecode(jsonData));
} else {
throw Exception('Request failed with status: ${response.statusCode}');
}
}