send method

  1. @override
Future<void> send(
  1. KuzzleRequest request
)
override

Sends a payload to the connected server

Implementation

@override
Future<void> send(KuzzleRequest request) async {
  final headers = {'Content-Type': 'application/json'};

  if (request.jwt != null) {
    headers['Authorization'] = 'Bearer ${request.jwt}';
  }

  if (request.volatile != null) {
    headers['x-kuzzle-volatile'] = jsonEncode(request.volatile);
  }

  final res = await _ioClient.post(
    Uri.parse('${uri.toString()}/_query'),
    headers: headers,
    body: jsonEncode(request),
  );

  emit(request.requestId!, [
    KuzzleResponse.fromJson(
        jsonDecode(utf8.decode(res.bodyBytes)) as Map<String, dynamic>)
  ]);
}