api<T extends NyApiService> function
dynamic
api<T extends NyApiService>(
- dynamic request(
- T 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 retryIf(
- DioException dioException
- bool? shouldSetAuthHeaders,
- dynamic onSuccess(
- Response response,
- dynamic data
- dynamic onError(
- DioException dioException
- Duration? cacheDuration,
- String? cacheKey,
- 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,
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(),
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,
onSuccess: onSuccess,
onError: onError,
cacheKey: cacheKey,
cacheDuration: cacheDuration,
shouldSetAuthHeaders: shouldSetAuthHeaders,
);