connectapi method
Implementation
Future<dynamic> connectapi(
String path, {
String method = "GET",
dynamic data,
}) async {
final resp = await request(
method,
"connectapi",
path,
api: true,
data: data,
);
if (resp.statusCode == 204) return null;
final decoded = jsonDecode(resp.body);
// Save for study purpose
if (_debugEnabled && _debugPath != null) {
try {
final fileName = path.replaceAll('/', '_').replaceAll('?', '_');
final file = File('$_debugPath/$fileName.json');
await file.parent.create(recursive: true);
await file.writeAsString(
JsonEncoder.withIndent(' ').convert(decoded),
);
} catch (e) {
// Ignore errors in saving
}
}
return decoded;
}