I am in the process of building a web SAAS App
I am doing the following:
Lemon Squeezy API – I have 6 subscription plans in total,
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
On Page Load – I am making 6 API calls (6 plans) to get the free trial periods for all the 6 plans
Question:
Rate Limiting – Lemon Squeezy has 300 API calls / min rate limiting
Should I implement caching? If yes, then how?
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
If i need to implement caching for API calls in my Custom Action API calls how do I do that?
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}');
}
}