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. Object? rawBody = _unset,
  8. Map<String, dynamic>? headers,
  9. Object? contentType = _unset,
  10. ResponseType? responseType,
  11. Object? connectTimeout = _unset,
  12. Object? receiveTimeout = _unset,
  13. Object? sendTimeout = _unset,
  14. Object? cancelToken = _unset,
  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,
  Object? rawBody = _unset,
  Map<String, dynamic>? headers,
  Object? contentType = _unset,
  ResponseType? responseType,
  Object? connectTimeout = _unset,
  Object? receiveTimeout = _unset,
  Object? sendTimeout = _unset,
  Object? cancelToken = _unset,
  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: identical(rawBody, _unset) ? this.rawBody : rawBody,
    headers: headers ?? this.headers,
    contentType: identical(contentType, _unset)
        ? this.contentType
        : contentType as String?,
    responseType: responseType ?? this.responseType,
    connectTimeout: identical(connectTimeout, _unset)
        ? this.connectTimeout
        : connectTimeout as Duration?,
    receiveTimeout: identical(receiveTimeout, _unset)
        ? this.receiveTimeout
        : receiveTimeout as Duration?,
    sendTimeout: identical(sendTimeout, _unset)
        ? this.sendTimeout
        : sendTimeout as Duration?,
    cancelToken: identical(cancelToken, _unset)
        ? this.cancelToken
        : cancelToken as CancelToken?,
    extra: extra ?? this.extra,
  );
}