send method

Future<Response> send(
  1. Uri uri,
  2. Request request
)

Sends the request to the given uri.

Implementation

Future<Response> send(Uri uri, Request request) async {
  final json = await _encode(request.document);
  final body = i.Body.text(json, utf8);
  final headers = i.Headers.from({
    'Accept': [mediaType],
    if (json.isNotEmpty) 'Content-Type': [mediaType],
    ...request.headers
  });
  final url = request.query.isEmpty
      ? uri
      : uri.replace(queryParameters: request.query.toQuery());
  final response =
      await _handler(i.Request(request.method, url, body, headers));

  final document = await _decode(response);
  return Response(response, document);
}