read function

Future<String> read(
  1. Uri url, {
  2. Map<String, String>? headers,
  3. Duration? timeout,
})

Sends an HTTP GET request with the given headers to the given URL and returns a Future that completes to the body of the response as a String.

The Future will emit a ClientException if the response doesn't have a success status code.

If timeout is not null the request will be aborted if it takes longer than the given duration to complete, and the returned future will complete as an error with a TimeoutException.

This automatically initializes a new BalanceClient and closes that client once the request is complete. If you're planning on making multiple requests to the same server, you should use a single BalanceClient for all of those requests.

For more fine-grained control over the request and response, use Request instead.

Implementation

Future<String> read(Uri url,
        {Map<String, String>? headers, Duration? timeout}) =>
    _withClient(
        (client) => client.read(url, headers: headers, timeout: timeout));