post method

  1. @override
Future<Either<Failure, Response>> post({
  1. required String endpoint,
  2. Object? data,
  3. Map<String, dynamic>? params,
  4. Duration? receiveTimeout,
  5. Duration? sendTimeout,
  6. Map<String, String>? headers,
  7. ProgressCallback? onSendProgress,
  8. ProgressCallback? onReceiveProgress,
  9. CancelToken? cancelToken,
  10. ResponseType? responseType,
  11. String? tag,
  12. bool showLoader = true,
})
override

Sends a POST request to endpoint.

Use for creating resources or submitting forms. Pass the request body as data (a Map, a model's .toJson(), or FormData for file uploads — though upload is easier for that).

Example:

final result = await _api.post(
  endpoint: '/auth/login',
  data: {'email': email, 'password': password},
);

Never auto-retried on a timeout: the server may already have processed it, and repeating it could create the same record twice.

Implementation

@override
Future<Either<Failure, Response>> post({
  required String endpoint,
  Object? data,
  Map<String, dynamic>? params,
  Duration? receiveTimeout,
  Duration? sendTimeout,
  Map<String, String>? headers,
  ProgressCallback? onSendProgress,
  ProgressCallback? onReceiveProgress,
  CancelToken? cancelToken,
  ResponseType? responseType,
  String? tag,
  bool showLoader = true,
}) {
  return _respond(
    HttpMethod.post,
    endpoint,
    data: data,
    params: params,
    headers: headers,
    tag: tag,
    cancelToken: cancelToken,
  );
}