execute method

Future<HttpResponse> execute(
  1. HttpRequest request
)

Send request to the API and return the response.

The request will not be sent immediately if its corresponding bucket is out of remaining requests or if the global rate limit has been hit. Instead, this method will wait until the rate limit has passed to send the request.

If the response has a status code of 2XX, a HttpResponseSuccess is returned.

If the response has a status code of 429, rate limit information is extracted from the response and the request is sent again after the rate limit passes. The response returned is that of the second request.

Otherwise, this method returns a HttpResponseError.

This method calls NyxxPlugin.interceptRequest on all plugins registered to the client which may intercept the request.

Implementation

Future<HttpResponse> execute(HttpRequest request) async {
  final executeFn = client.options.plugins.fold(
    _execute,
    (previousValue, plugin) => (request) => plugin.interceptRequest(client, request, previousValue),
  );
  return await executeFn(request);
}