AdapterRequest class

author: ZhengZaiHong email:1096877329@qq.com date: 2026-04-21 16:03 describe: request adapter Unified request configuration model.

This class encapsulates all the information needed to make an HTTP request, abstracting away the differences between various HTTP client libraries.

Basic Usage

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

RESTful Parameters

Use pathParams for RESTful URL parameters:

final request = AdapterRequest(
  baseUrl: 'https://api.example.com',
  path: '/users/{id}/posts/{postId}',
  method: HttpMethod.get,
  pathParams: {'id': '123', 'postId': '456'},
);
// Results in: https://api.example.com/users/123/posts/456

Query Parameters

Use queryParams for URL query strings:

final request = AdapterRequest(
  baseUrl: 'https://api.example.com',
  path: '/users',
  method: HttpMethod.get,
  queryParams: {'page': 1, 'limit': 20},
);
// Results in: https://api.example.com/users?page=1&limit=20

Request Body

Use bodyParams for structured data or rawBody for raw data:

// JSON body
final request = AdapterRequest(
  baseUrl: 'https://api.example.com',
  path: '/users',
  method: HttpMethod.post,
  bodyParams: {'name': 'John', 'email': 'john@example.com'},
  contentType: 'application/json',
);

// Raw body
final request = AdapterRequest(
  baseUrl: 'https://api.example.com',
  path: '/upload',
  method: HttpMethod.post,
  rawBody: 'raw text data',
  contentType: 'text/plain',
);

See also:

Constructors

AdapterRequest({required String baseUrl, required String path, required HttpMethod method, Map<String, dynamic> pathParams = const {}, Map<String, dynamic> queryParams = const {}, Map<String, dynamic> bodyParams = const {}, dynamic rawBody, Map<String, dynamic> headers = const {}, String? contentType, ResponseType responseType = ResponseType.json, Duration? connectTimeout, Duration? receiveTimeout, Duration? sendTimeout, CancelToken? cancelToken, Map<String, dynamic> extra = const {}})
Creates a new AdapterRequest.
const

Properties

baseUrl String
Base URL of the API.
final
bodyParams Map<String, dynamic>
Request body parameters (for structured data).
final
cancelToken CancelToken?
Cancel token for request cancellation.
final
connectTimeout Duration?
Connection timeout duration.
final
contentType String?
Content-Type header value.
final
extra Map<String, dynamic>
Extra configuration data.
final
hashCode int
The hash code for this object.
no setterinherited
headers Map<String, dynamic>
Request headers.
final
method HttpMethod
HTTP method for the request.
final
path String
Request path, optionally with RESTful parameters.
final
pathParams Map<String, dynamic>
RESTful path parameters.
final
queryParams Map<String, dynamic>
URL query parameters.
final
rawBody → dynamic
Raw request body (for unstructured data).
final
receiveTimeout Duration?
Receive timeout duration.
final
responseType ResponseType
Expected response type.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sendTimeout Duration?
Send timeout duration.
final

Methods

buildFullUrl() String
Builds the full URL by combining baseUrl, path, and pathParams.
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}) AdapterRequest
Creates a copy of this request with some fields replaced.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited