request method

Future<Map<String, dynamic>> request(
  1. String url,
  2. dynamic data
)

Perform the specified http request and return the response data. @param {string} url The server URL that will be used for the request. @param {object} data The data to be sent as the request body. @returns {Promise<any>} The response body that was provided by the server. @private

Implementation

Future<Map<String, dynamic>> request(String url, dynamic data) async {
  final res = await defaultFetch(
    endpoint: url,
    defaultHost: host,
    baseHeaders: {'Content-Type': 'application/json;charset=utf-8'},
    cbor: false,
    body: jsonEncode(data),
  );
  final response = FetchResponse.fromJson(res);
  if (response.ok) {
    return jsonDecode(response.body);
  } else {
    throw TransactionError(
      response.statusText,
      response.statusCode,
      detail: response.body.isNotEmpty
          ? jsonDecode(response.body)
          : response.body,
    );
  }
}