37 lines
1.0 KiB
Dart
37 lines
1.0 KiB
Dart
import 'package:dio/dio.dart';
|
|
|
|
class ApiClient {
|
|
final Dio _dio = Dio();
|
|
final String _baseUrl = 'https://api.freekake.com/';
|
|
|
|
ApiClient() {
|
|
_dio.options.baseUrl = _baseUrl;
|
|
_dio.options.connectTimeout = const Duration(seconds: 5);
|
|
_dio.options.receiveTimeout = const Duration(seconds: 3);
|
|
|
|
_dio.interceptors.add(
|
|
InterceptorsWrapper(
|
|
onRequest: (options, handler) {
|
|
print('REQUEST[${options.method}] => PATH: ${options.path}');
|
|
// options.headers['Authorization'] = 'Bearer your_token_here';
|
|
return handler.next(options);
|
|
},
|
|
onResponse: (response, handler) {
|
|
print(
|
|
'RESPONSE[${response.statusCode}] => PATH: ${response.requestOptions.path}',
|
|
);
|
|
return handler.next(response);
|
|
},
|
|
onError: (DioException e, handler) {
|
|
print(
|
|
'ERROR[${e.response?.statusCode}] => PATH: ${e.requestOptions.path}',
|
|
);
|
|
return handler.next(e);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
Dio get dio => _dio;
|
|
}
|