API Call Caching - API implemented as Custom Action

Database & APIs

I am in the process of building a web SAAS App

I am doing the following:

  1. Lemon Squeezy API –  I have 6 subscription plans  in total,

  2. i want to check if each has a free trial , if yes then display the Free Trial period on the Subscribe button on Subscription Plan Page

  3. On Page Load – I am making 6 API calls (6 plans) to get the free trial periods for all the 6 plans

Question:

  1. Rate Limiting – Lemon Squeezy has 300 API calls / min rate limiting

  2. Should I implement caching? If yes, then how?

  3. Custom Actions (API Calls) – I am using my own custom actions to make the API calls & not using Flutter Flow’s built in API call feature

  4. If i need to implement caching for API calls in my Custom Action API calls how do I do that?

  5. Sample API code in custom action attached

Future<dynamic> apiCheckIfVarientHasFreeTrialLemonSqueezyAction(
    String? varientId, String apikey) async {
  final url = 'https://api.lemonsqueezy.com/v1/variants/$varientId/price-model';
  final response = await http.get(
    Uri.parse(url),
    headers: {
      'Accept': 'application/vnd.api+json',
      'Content-Type': 'application/vnd.api+json',
      'Authorization': 'Bearer $apikey'
    },
  );

  if (response.statusCode == 200) {
    // return jsonDecode(response.body)['data'];
    return json.decode(response.body);
  } else {
    final responseBody = jsonDecode(response.body);
    final errorDetail = responseBody['errors']?[0]['detail'] ?? 'Unknown error';
    final errorTitle = responseBody['errors']?[0]['title'] ?? 'Error';
    final errorStatus =
        responseBody['errors']?[0]['status'] ?? response.statusCode.toString();
    throw Exception(
        'Failed to create checkout: $errorTitle - $errorDetail (Status: $errorStatus)');
    // throw Exception('Failed to fetch subscription: ${response.reasonPhrase}');
  }
}

What have you tried so far?

Nothing as i need help

Did you check FlutterFlow's Documentation for this topic?
No
2
7 replies