callRESTAPI method

Future<Response> callRESTAPI({
  1. required String endpoint,
  2. required String method,
  3. Map<String, dynamic>? variables,
})

callRESTAPI is used when making unauthenticated REST backend calls

Implementation

Future<Response> callRESTAPI({
  required String endpoint,
  required String method,
  Map<String, dynamic>? variables,
}) async {
  final Request request = Request(method, this.fromUriOrString(endpoint));

  request.body = json.encode(variables);
  return Response.fromStream(
    await this.send(request).timeout(
      const Duration(seconds: kRequestTimeoutSeconds),
      onTimeout: () {
        final String timeoutInput = json.encode(kTimeoutResponsePayload);
        final List<int> body = utf8.encode(timeoutInput);
        return StreamedResponse(
          ByteStream.fromBytes(body),
          408,
          headers: this.requestHeaders,
        );
      },
    ),
  );
}