articles_api.dart 935 Bytes
Newer Older
yenisleydi committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
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 {
    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'};
    }
  }
yenisleydi committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

  Future<Map<String, dynamic>> searchArticles(String query) async {
        String url = '${api.apiApp}/articulo?nombre="$query"';

    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'};
    }
  }
yenisleydi committed
35
}