OpenMediacenterMobileFlutter/lib/api/api.dart

32 lines
811 B
Dart
Raw Normal View History

import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:openmediacentermobile/api/token.dart';
import 'package:openmediacentermobile/log/log.dart';
class API {
static Future<String> query(
String apinode, String action, Object payload) async {
final Completer<String> cmpl = Completer();
final t = await Token.getInstance().getToken();
Log.d(t);
if (t != null) {
final resp = await http.post(
Uri.parse(t.domain + '/api/$apinode/$action'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Token': t.token
},
body: jsonEncode(payload),
);
cmpl.complete(resp.body);
} else {
cmpl.complete("");
}
return cmpl.future;
}
}