post method

Future<int> post(
  1. DataPoint data
)

Uploads data.

Returns the server-generated ID for this data point.

Implementation

Future<int> post(DataPoint data) async {
  final response =
      await service._post(dataEndpointUri, body: json.encode(data));

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

  if ((httpStatusCode == HttpStatus.ok) ||
      (httpStatusCode == HttpStatus.created)) {
    return responseJson["id"] as int;
  }

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