postJson method

Future<TestResponse> postJson(
  1. String uri,
  2. dynamic body, {
  3. Map<String, List<String>>? headers,
})

Sends a POST request with a JSON body to the specified uri.

This method sets the 'Content-Type' header to 'application/json'.

uri is the endpoint to send the request to. body is the JSON payload to be sent (can be a Map, List, or primitive value). headers is an optional parameter to provide additional headers.

Returns a TestResponse that can be used for assertions.

Example:

final response = await client.postJson('/users', {
  'name': 'John Doe',
  'email': 'john@example.com'
});

Implementation

Future<TestResponse> postJson(
  String uri,
  dynamic body, {
  Map<String, List<String>>? headers,
}) {
  return _transport.sendRequest(
    'POST',
    uri,
    headers: {
      ...?headers,
      'Content-Type': ['application/json'],
    },
    body: body,
    options: _options,
  );
}