37 lines
986 B
Dart
37 lines
986 B
Dart
import 'package:autos/core/constants/api_endpoints.dart';
|
|
import 'package:dio/dio.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
class ApiService {
|
|
final Dio _dio;
|
|
|
|
ApiService({String? baseUrl})
|
|
: _dio = Dio(
|
|
BaseOptions(
|
|
baseUrl: baseUrl ?? ApiEndpoints.baseUrl,
|
|
connectTimeout: ApiEndpoints.connectTimeout,
|
|
receiveTimeout: ApiEndpoints.receiveTimeout,
|
|
headers: ApiEndpoints.defaultHeaders,
|
|
),
|
|
) {
|
|
// Add logging interceptor in debug mode
|
|
if (kDebugMode) {
|
|
_dio.interceptors.add(
|
|
LogInterceptor(requestBody: true, responseBody: true),
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<Response> post(
|
|
String endpoint,
|
|
Map<String, dynamic> data, {
|
|
Options? options,
|
|
}) async {
|
|
return await _dio.post(endpoint, data: data, options: options);
|
|
}
|
|
|
|
Future<Response> get(String endpoint, {Map<String, dynamic>? params}) async {
|
|
return await _dio.get(endpoint, queryParameters: params);
|
|
}
|
|
}
|