getProducts method

Future<List<Product>> getProducts({
  1. String? query,
  2. int? limit,
})

Gets all the products.

Implementation

Future<List<Product>> getProducts({String? query, int? limit}) async {
  final response = await _context.client.get(
    Uri.https(
      authority,
      '$path/products',
      {
        if (query != null) 'query': query.toString(),
        if (limit != null) 'limit': limit.toString(),
      },
    ),
  );

  ClientException.checkIsSuccessStatusCode(response);

  return (json.decode(response.body) as List)
      .map((e) => Product.fromJson(e))
      .toList();
}