fetchOne method

Future<T> fetchOne(
  1. String endpoint,
  2. int id
)

Implementation

Future<T> fetchOne(String endpoint, int id) async {
  final response = await http.get(Uri.parse('$baseUrl/$endpoint/$id'));

  if (response.statusCode == 200) {
    final Map<String, dynamic> data = json.decode(response.body);
    return this.instance.fromJson(data);
  } else {
    throw Exception('Erro na chamada de serviço: ${response.statusCode}');
  }
}