copyWith method

AdapterRequest copyWith({
  1. String? baseUrl,
  2. String? path,
  3. HttpMethod? method,
  4. Map<String, dynamic>? pathParams,
  5. Map<String, dynamic>? queryParams,
  6. Map<String, dynamic>? bodyParams,
  7. dynamic rawBody,
  8. Map<String, dynamic>? headers,
  9. String? contentType,
  10. ResponseType? responseType,
  11. Duration? connectTimeout,
  12. Duration? receiveTimeout,
  13. Duration? sendTimeout,
  14. CancelToken? cancelToken,
  15. Map<String, dynamic>? extra,
})

Creates a copy of this request with some fields replaced.

This is useful for modifying requests in interceptors or creating variations of a base request.

Example:

final baseRequest = AdapterRequest(
  baseUrl: 'https://api.example.com',
  path: '/users',
  method: HttpMethod.get,
);

// Add authentication header
final authenticatedRequest = baseRequest.copyWith(
  headers: {...baseRequest.headers, 'Authorization': 'Bearer token'},
);

Implementation

AdapterRequest copyWith({
  String? baseUrl,
  String? path,
  HttpMethod? method,
  Map<String, dynamic>? pathParams,
  Map<String, dynamic>? queryParams,
  Map<String, dynamic>? bodyParams,
  dynamic rawBody,
  Map<String, dynamic>? headers,
  String? contentType,
  ResponseType? responseType,
  Duration? connectTimeout,
  Duration? receiveTimeout,
  Duration? sendTimeout,
  CancelToken? cancelToken,
  Map<String, dynamic>? extra,
}) {
  return AdapterRequest(
    baseUrl: baseUrl ?? this.baseUrl,
    path: path ?? this.path,
    method: method ?? this.method,
    pathParams: pathParams ?? this.pathParams,
    queryParams: queryParams ?? this.queryParams,
    bodyParams: bodyParams ?? this.bodyParams,
    rawBody: rawBody ?? this.rawBody,
    headers: headers ?? this.headers,
    contentType: contentType ?? this.contentType,
    responseType: responseType ?? this.responseType,
    connectTimeout: connectTimeout ?? this.connectTimeout,
    receiveTimeout: receiveTimeout ?? this.receiveTimeout,
    sendTimeout: sendTimeout ?? this.sendTimeout,
    cancelToken: cancelToken ?? this.cancelToken,
    extra: extra ?? this.extra,
  );
}