performHttpRequest method

  1. @override
Future<Map<String, dynamic>> performHttpRequest({
  1. required String method,
  2. required String url,
  3. required Map<String, String> headers,
  4. dynamic body,
  5. required Duration timeout,
})
override

Implementation

@override
Future<Map<String, dynamic>> performHttpRequest({
  required String method,
  required String url,
  required Map<String, String> headers,
  dynamic body,
  required Duration timeout,
}) async {
  if (!_isInitialized) {
    await initialize();
  }

  try {
    final options = <String, dynamic>{
      'method': method,
      'url': url,
      'headers': headers,
      'body': body,
      'timeout': timeout.inMilliseconds,
    }.jsify() as JSObject;

    final requestPromise = _performWasmRequest(options);
    if (requestPromise == null) {
      throw const FittorWasmException(
          'WasmHttpClient.performRequest not available');
    }

    final result = await requestPromise.toDart;
    return (result as JSObject).dartify() as Map<String, dynamic>;
  } catch (e) {
    throw FittorWasmException('WASM request failed: $e', e);
  }
}