articles_api.dart 617 Bytes
Newer Older
yenisleydi committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'package:primer_practica/environments/urls.dart' as api;

class ArticlesApi {
  Future<Map<String, dynamic>> getArticles() async {
    // Usa la constante `apiBaseUrl` de `urls.dart` para construir la URL
    String url = '${api.apiApp}/articulo?offset=0&max=100';

    if (kDebugMode) {
      print('Url -> $url');
    }

    try {
      final resp = await http.get(Uri.parse(url));
      return {"statusCode": resp.statusCode, "body": resp.body};
    } catch (e) {
      return {"statusCode": 501, "body": '$e'};
    }
  }
}