httpRequest method

Future<Map> httpRequest (Uri uri, Map request)

Processes the HTTP request returning the HTTP response as a map

Implementation

Future<Map> httpRequest(Uri uri, Map request) {
  final completer = Completer<Map>();
  _client.postUrl(uri).then((HttpClientRequest req) {
    final payload = json.encode(request);
    req.headers.add(HttpHeaders.contentTypeHeader, jsonMimeType);
    req.contentLength = payload.length;
    req.write(payload);
    req.close().then((HttpClientResponse resp) {
      resp.listen((data) {
        final Map payload = json.decode(String.fromCharCodes(data));
        completer.complete(payload);
      }, onError: (e) {
        print(e);
      }, onDone: () {
        _client.close();
      });
    });
  }, onError: (e) {
    print(e);
  });
  return completer.future;
}