get method
Reads the collection referenced by this CollectionReference from the server.
If no collection exists on the server (yet), this local CollectionReference is returned.
Implementation
Future<CollectionReference> get() async {
final restHeaders = headers;
debug('REQUEST: GET $collectionUri\n');
final response =
await httpr.get(Uri.encodeFull(collectionUri), headers: restHeaders);
int httpStatusCode = response.statusCode;
debug('RESPONSE: $httpStatusCode\n${response.body}\n');
Map<String, dynamic> responseJson =
json.decode(response.body) as Map<String, dynamic>;
if (httpStatusCode == HttpStatus.ok) {
return this
.._id = responseJson['id'] as int
.._path = responseJson['name'].toString();
}
// All other cases are treated as an error.
throw CarpServiceException(
httpStatus: HTTPStatus(httpStatusCode, response.reasonPhrase),
message: responseJson['message'].toString(),
path: responseJson["path"].toString(),
);
}