api<T extends NyApiService> function

dynamic api<T extends NyApiService>(
  1. dynamic request(
    1. T request
    ), {
  2. BuildContext? context,
  3. Map<String, dynamic> headers = const {},
  4. String? bearerToken,
  5. String? baseUrl,
  6. int? page,
  7. String? queryNamePage,
  8. String? queryNamePerPage,
  9. int? perPage,
  10. int? retry,
  11. Duration? retryDelay,
  12. bool retryIf(
    1. DioException dioException
    )?,
  13. bool? shouldSetAuthHeaders,
  14. 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

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