put method

Future<Response> put(
  1. String url, {
  2. Map<String, String>? headers,
  3. Object? body,
  4. Encoding? encoding,
})

Sends an HTTP PUT request with the given headers and body to the given url.

Implementation

Future<http.Response> put(
  String url, {
  Map<String, String>? headers,
  Object? body,
  Encoding? encoding,
}) async {
  // calling the http PUT method using the retry approach
  final http.Response response = await retry(
    () => client
        .put(
          Uri.parse(Uri.encodeFull(url)),
          headers: headers,
          body: body,
          encoding: encoding,
        )
        .timeout(const Duration(seconds: 20)),
    delayFactor: const Duration(seconds: 5),
    maxAttempts: 15,
    retryIf: (e) => e is SocketException || e is TimeoutException,
    onRetry: (e) => print('${e.runtimeType} - Retrying to PUT $url'),
  );
  return response;
}