printHttpRequest function

void printHttpRequest({
  1. required String method,
  2. required String url,
  3. Map<String, Object?>? headers,
  4. Object? body,
  5. Iterable<String>? files,
  6. String? tag = 'HTTP',
})

Logs an outgoing HTTP request without coupling to http or dio.

Implementation

void printHttpRequest({
  required String method,
  required String url,
  Map<String, Object?>? headers,
  Object? body,
  Iterable<String>? files,
  String? tag = 'HTTP',
}) {
  printfBox(
    '$method REQUEST',
    [
      'URL     : $url',
      if (headers != null && headers.isNotEmpty) 'HEADERS : $headers',
      if (body != null) 'BODY    : ${_formatPayload(body)}',
      if (files != null && files.isNotEmpty) 'FILES   : ${files.join(', ')}',
    ].join('\n'),
    level: PrintfLevel.info,
    tag: tag,
  );
}