/
MPaidos
/
MobilePO
Обзор
Документация
Войти
/
MPaidos
/
MobilePO
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
lib/services/api_client.dart
36 строк
1011 B
MPaidos
Добавить интеграцию API, русские советы и документацию для защиты.
02 июн 2026, 17:33
02 июн 2026, 17:33
c726c09
Код
Авторство
О чём код?
import 'dart:convert'; import 'package:http/http.dart' as http; import '../config/api_config.dart'; class ApiException implements Exception { ApiException(this.statusCode, this.body); final int statusCode; final String body; @override String toString() => 'HTTP $statusCode'; } /// Общий HTTP-клиент для GET-запросов с JSON-ответом. class ApiClient { ApiClient({http.Client? client}) : _client = client ?? http.Client(); final http.Client _client; Future<Map<String, dynamic>> getJson(String url) async { final response = await _client.get(Uri.parse(url)).timeout(ApiConfig.timeout); if (response.statusCode < 200 || response.statusCode >= 300) { throw ApiException(response.statusCode, response.body); } final decoded = jsonDecode(response.body); if (decoded is! Map<String, dynamic>) { throw const FormatException('Ожидался JSON-объект'); } return decoded; } void dispose() => _client.close(); }