putDocument method

Future putDocument(
  1. String? id,
  2. JsonObjectLite? document, [
  3. String? rev
])

PUT's to the specified document.

For an update the revision must be specified, this can be in the document body as a _rev parameter or specified in the call in which case this will be added to the document body.

Implementation

Future<dynamic> putDocument(
    String? id, jsonobject.JsonObjectLite<dynamic>? document,
    [String? rev]) {
  if ((id == null) || (document == null)) {
    return _raiseException(WiltException.putDocNoIdBody);
  }

  // Check for a revision
  String jsonData;

  try {
    if (rev != null) {
      jsonData = WiltUserUtils.addDocumentRev(document, rev);
    } else {
      jsonData = json.encode(document);
    }
  } on Exception {
    return _raiseException(WiltException.putDocCantStringify);
  }

  final url = _conditionUrl(id);
  return _httpRequest(putDocumentt, url, data: jsonData);
}