api<T extends NyApiService> function

Future api<T extends NyApiService>(
  1. dynamic request(
    1. T request
    ), {
  2. Map<String, dynamic> headers = const {},
  3. String? bearerToken,
  4. String? baseUrl,
  5. int? page,
  6. String? queryNamePage,
  7. String? queryNamePerPage,
  8. int? perPage,
  9. int retry = 0,
  10. Duration? retryDelay,
  11. bool retryIf(
    1. DioException dioException
    )?,
  12. bool? shouldSetAuthHeaders,
  13. dynamic onSuccess(
    1. Response response,
    2. dynamic data
    )?,
  14. dynamic onError(
    1. DioException dioException
    )?,
  15. Duration? cacheDuration,
  16. String? cacheKey,
  17. List<Type> events = const [],
})

api helper Example:

await api<ApiService>((request) => request.get("https://jsonplaceholder.typicode.com/posts"));

The above example will send an API request and return the data.

Implementation

Future api<T extends NyApiService>(
  dynamic Function(T request) request, {
  Map<String, dynamic> headers = const {},
  String? bearerToken,
  String? baseUrl,
  int? page,
  String? queryNamePage,
  String? queryNamePerPage,
  int? perPage,
  int retry = 0,
  Duration? retryDelay,
  bool Function(DioException dioException)? retryIf,
  bool? shouldSetAuthHeaders,
  Function(Response response, dynamic data)? onSuccess,
  Function(DioException dioException)? onError,
  Duration? cacheDuration,
  String? cacheKey,
  List<Type> events = const [],
}) async => await nyApi<T>(
  request: request,
  apiDecoders: Nylo.apiDecoders(),
  headers: headers,
  bearerToken: bearerToken,
  baseUrl: baseUrl,
  events: events,
  page: page,
  perPage: perPage,
  queryParamPage: queryNamePage ?? "page",
  queryParamPerPage: queryNamePerPage,
  retry: retry,
  retryDelay: retryDelay,
  retryIf: retryIf,
  onSuccess: onSuccess,
  onError: onError,
  cacheKey: cacheKey,
  cacheDuration: cacheDuration,
  shouldSetAuthHeaders: shouldSetAuthHeaders,
);