40 lines
1.2 KiB
Dart
40 lines
1.2 KiB
Dart
import 'dart:convert';
|
|
import 'package:http/http.dart' as http;
|
|
import '../constants/api_constants.dart';
|
|
import 'auth_service.dart';
|
|
|
|
class HttpService {
|
|
static Future<http.Response> get(String endpoint) async {
|
|
final headers = await AuthService.getAuthHeaders();
|
|
return await http.get(
|
|
Uri.parse('${ApiConstants.baseUrl}$endpoint'),
|
|
headers: headers,
|
|
);
|
|
}
|
|
|
|
static Future<http.Response> post(String endpoint, Map<String, dynamic> body) async {
|
|
final headers = await AuthService.getAuthHeaders();
|
|
return await http.post(
|
|
Uri.parse('${ApiConstants.baseUrl}$endpoint'),
|
|
headers: headers,
|
|
body: jsonEncode(body),
|
|
);
|
|
}
|
|
|
|
static Future<http.Response> put(String endpoint, Map<String, dynamic> body) async {
|
|
final headers = await AuthService.getAuthHeaders();
|
|
return await http.put(
|
|
Uri.parse('${ApiConstants.baseUrl}$endpoint'),
|
|
headers: headers,
|
|
body: jsonEncode(body),
|
|
);
|
|
}
|
|
|
|
static Future<http.Response> delete(String endpoint) async {
|
|
final headers = await AuthService.getAuthHeaders();
|
|
return await http.delete(
|
|
Uri.parse('${ApiConstants.baseUrl}$endpoint'),
|
|
headers: headers,
|
|
);
|
|
}
|
|
} |