get method

Future<DataPoint> get(
  1. int id
)

Get a DataPoint based on its id from the CARP backend.

Implementation

Future<DataPoint> get(int id) async {
  final url = "$dataEndpointUri/$id";
  final response = await service._get(url);

  int httpStatusCode = response.statusCode;
  Map<String, dynamic> responseJson =
      json.decode(response.body) as Map<String, dynamic>;

  if (httpStatusCode == HttpStatus.ok) {
    return DataPoint.fromJson(responseJson);
  }

  // All other cases are treated as an error.
  throw CarpServiceException.fromMap(httpStatusCode, responseJson);
}