delete method

Future<void> delete(
  1. int id
)

Delete a data point with the given id.

Returns on success. Throws a CarpServiceException if data point is not found or otherwise unsuccessful.

Implementation

Future<void> delete(int id) async {
  String url = "$dataEndpointUri/$id";

  http.Response response =
      await httpr.delete(Uri.encodeFull(url), headers: headers);
  final int httpStatusCode = response.statusCode;

  if (httpStatusCode == HttpStatus.ok) return;

  // All other cases are treated as an error.
  final Map<String, dynamic> responseJson =
      json.decode(response.body) as Map<String, dynamic>;
  throw CarpServiceException(
    httpStatus: HTTPStatus(httpStatusCode, response.reasonPhrase),
    message: responseJson["message"].toString(),
    path: responseJson["path"].toString(),
  );
}