import 'dart:async'; import 'dart:convert'; import 'package:http/http.dart' as http; import 'token.dart'; class TokenException implements Exception { String wdExpMsg() => 'Invalid token in storage!'; } class API { static Future query( String apinode, String action, Object payload) async { final t = await Token.getInstance().getToken(); if (t != null) { final resp = await http.post( Uri.parse(t.domain + '/api/$apinode/$action'), headers: { 'Content-Type': 'application/json; charset=UTF-8', 'Token': t.token }, body: jsonEncode(payload), ); return resp.body; } else { throw TokenException(); } } }