post<T> function
Future<Response<T> >
post<T>(
- String unencodedPath, {
- Protocol protocol = Protocol.https,
- String? service,
- Map<
String, String> ? headers, - Map<
String, dynamic> ? parameters, - Map<
String, dynamic> ? body, - Duration timeout = const Duration(seconds: 10),
- ResponseDataBuilder<
T> ? to, - ResponseDataAdaptor? adaptor,
- PostClient? postClient,
- Client? client,
Implementation
Future<Response<T>> post<T>(
final String unencodedPath, {
final Protocol protocol = Protocol.https,
final String? service,
final Map<String, String>? headers,
final Map<String, dynamic>? parameters,
final Map<String, dynamic>? body,
final Duration timeout = const Duration(seconds: 10),
final type.ResponseDataBuilder<T>? to,
final type.ResponseDataAdaptor? adaptor,
final type.PostClient? postClient,
final http.Client? client,
}) async => _buildResponse<T>(
checkStatus(
await util.executePost(
util
.getUriFactory(protocol)
.call(
service ?? defaultService,
unencodedPath,
util.toQueryParameters(parameters),
),
headers: {'Content-Type': 'application/json; charset=UTF-8'}
..addAll(headers ?? {}),
//! Use the body-specific cleaner so that explicitly empty collections
//! (e.g. threadgate `allow: []`) survive; only `null` values are removed.
//! `removeNullValues` would prune empty `[]`/`{}`, silently changing the
//! meaning of a request body.
body: body != null
? jsonEncode(util.removeNullValuesFromBody(body) ?? {})
: null,
encoding: utf8,
timeout: timeout,
postClient: postClient,
client: client,
),
),
to,
adaptor,
);