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 {
  String url = "$dataEndpointUri/$id";

  // GET the data point from the CARP web service
  http.Response response =
      await httpr.get(Uri.encodeFull(url), headers: headers);

  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(
    httpStatus: HTTPStatus(httpStatusCode, response.reasonPhrase),
    message: responseJson["message"].toString(),
    path: responseJson["path"].toString(),
  );
}