auth method
Implementation
Future<Map> auth(String endpoint, String apiKey) async {
try {
final response = await http.post(
Uri.parse('$apiUrl/$endpoint'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({ 'key': apiKey }),
);
if (response.statusCode == 200) {
Map result = (jsonDecode(response.body) ?? {}) as Map;
return result;
} else {
throw 'Error auth $apiUrl/$endpoint: ${response.body.toString()}';
}
} catch (error){
return {'type': 'error', 'message' : '$error'};
}
}