post method

Future<DbResponse> post(
  1. dynamic body, {
  2. String? path,
  3. PrintMode? printMode,
  4. bool eTag = false,
})

Sends a post requests to the database to create new data.

Tries to create a new child entry at path, or the whole virtual root, if not set. The target location must be an object or array for this to work. If posting to an array, the body is simply appended. For objects, a new random key is generated and the body added to the object under that key. In either cases, the returned result contains the id of the newly created entry.

The printMode can be used to control how data is formatted by the server.

Finally, the eTag parameter can be set to true to request an eTag for the given data.

Implementation

Future<DbResponse> post(
  dynamic body, {
  String? path,
  PrintMode? printMode,
  bool eTag = false,
}) async {
  final response = await client.post(
    _buildUri(
      path: path,
      printMode: printMode,
    ),
    body: json.encode(body),
    headers: _buildHeaders(
      hasBody: true,
      eTag: eTag,
    ),
  );
  return _parseResponse(response, eTag);
}