post abstract method

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. bool showLoader = true,
})

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).

Example:

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

File upload example:

final result = await _api.post(
  endpoint: '/upload',
  data: FormData.fromMap({
    'file': await MultipartFile.fromFile(filePath),
  }),
  onSendProgress: (sent, total) => print('${sent / total * 100}%'),
);

Implementation

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,
  bool showLoader = true,
});