request<TBodyType, TResponseType> method

Future<TResponseType> request<TBodyType, TResponseType>(
  1. String url,
  2. TBodyType body,
  3. TResponseType fromJson(
    1. Map<String, dynamic>
    )
)

Implementation

Future<TResponseType> request<TBodyType, TResponseType>(
  String url,
  TBodyType body,
  TResponseType Function(Map<String, dynamic>) fromJson,
) async {
  final fullUrl = '${config.baseUrl}$url';
  final stringifiedBody = jsonEncode(body);
  final stamp = await stamper.stamp(stringifiedBody);

  final response = await transport.post(
    url: fullUrl,
    body: stringifiedBody,
    headers: {
      stamp.stampHeaderName: stamp.stampHeaderValue,
      'X-Client-Version': VERSION,
    },
  );

  if (response.statusCode != 200) {
    throw ZeroXKeyRequestError(
      GrpcStatus.fromJson(jsonDecode(response.body)),
    );
  }

  final decodedJson = jsonDecode(response.body) as Map<String, dynamic>;
  return fromJson(decodedJson);
}