post<T> function

Future<Response<T>> post<T>(
  1. String unencodedPath, {
  2. Protocol protocol = Protocol.https,
  3. String? service,
  4. Map<String, String>? headers,
  5. Map<String, dynamic>? parameters,
  6. Map<String, dynamic>? body,
  7. Duration timeout = const Duration(seconds: 10),
  8. ResponseDataBuilder<T>? to,
  9. ResponseDataAdaptor? adaptor,
  10. PostClient? postClient,
  11. 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,
);