getDocumentByKey method

Future<DocumentResponse> getDocumentByKey(
  1. String collection,
  2. String documentKey, {
  3. String? ifNoneMatchRevision,
  4. String? ifMatchRevision,
  5. Transaction? transaction,
})

Reads a single document https://www.arangodb.com/docs/3.4/http/document-working-with-documents.html#read-document

If ifNoneMatchRevision was given and this revision equals the latest version of found document, then server will return 304 status code and this driver will return empty Map.

If ifMatchRevision was given and document with this revision was not found, then not empty Map will returned, but with code=412 and error=true and corresponding errorMessage.

Implementation

Future<DocumentResponse> getDocumentByKey(
  String collection,
  String documentKey, {
  String? ifNoneMatchRevision,
  String? ifMatchRevision,
  Transaction? transaction,
}) async {
  var result = await _httpGet(
    ['_db', db, '_api', 'document', collection, documentKey],
    headers: _addTransactionHeader(transaction, headers: {
      'accept': 'application/json',
      'If-None-Match': ifNoneMatchRevision,
      'If-Match': ifMatchRevision,
    }),
  );
  if (result == null || result.length == 0) {
    return DocumentResponse(
        result: Result.empty(), document: <String, dynamic>{});
  }
  var ret = DocumentResponse(
    document: result,
    result: _toResult(result),
  );
  return ret;
}