execute method

Future<TestResponse> execute(
  1. String method,
  2. String path, {
  3. dynamic body,
  4. Map<String, dynamic>? headers,
  5. Map<String, dynamic>? query,
})

Executes an HTTP request with this agent.

The method is request method (e.g., GET, POST) and is case-insensitive. Prefer to use methods like get or post.

path is the path fo the resource on the server being tested. It is appended to baseURL. If there is no leading slash in the path, one is added to separate the base URL from the path.

body is encoded according to contentType prior to the request being sent (the default encodes body as JSON). If body is null, none is sent.

The headers of the request are formed by combining headers and the Agent.headers. If headers is null, the request's headers are only those in Agent.headers.

If query is non-null, each value is URI-encoded and then the map is encoding as the request URI's query string.

Implementation

Future<TestResponse> execute(String method, String path,
    {dynamic body,
    Map<String, dynamic>? headers,
    Map<String, dynamic>? query}) {
  final req = request(path)
    ..body = body
    ..query = query;

  if (headers != null) {
    req.headers.addAll(headers);
  }

  return req.method(method);
}