invoke method

Future<HttpClientResponse> invoke(
  1. String path, {
  2. String method = 'GET',
  3. Object? body,
  4. Map<String, String> headers = const {'accept' : 'application/json'},
  5. int status = 200,
})

Implementation

Future<HttpClientResponse> invoke(
  String path, {
  String method = 'GET',
  Object? body,
  Map<String, String> headers = const {'accept': 'application/json'},
  int status = 200,
}) async {
  final client = HttpClient();
  final uri = Uri.parse('$address$path');
  final req = await client.openUrl(method, uri);
  headers.forEach((key, value) {
    req.headers.add(key, value);
  });
  body?.let(req.write);
  var response = await req.close();
  if (response.statusCode != status) {
    var message = 'Expecting status $status but got '
        '${response.statusCode} on $method $uri.';
    if (!hasMatched()) {
      message += '\n ${getMismatchJson()}';
    }
    throw PactException(message);
  }
  return response;
}