execute method

Future<RestResponse> execute(
  1. RestRequest restRequest
)

Use this method to execute requests, Receives a single argument of RestRequest, which represents the requests parameters, and returns RestResponse as a result. When you are calling the RestClient.execute method the ordering of the request pipeline is the following,

RestClient.execute -> RestRequestConverter.toRow -> RestMiddleware.next -> RestRequestExecutor.execute -> RestMiddleware.next -> RestResponseConverter.fromRow

Here are the descriptions of each pace in the request execution. RestClient.execute starts the request. RestRequestConverter.toRow converts the RestRequest to RestRowRequest. RestMiddleware.next this calls all the request middlewares in the chain. RestRequestExecutor.execute handle the http request and returns RestRowResponse. RestMiddleware.next this calls all the response middlewares in the chain. RestResponseConverter.fromRow converts the RestRowRequest to RestRequest. eventually returns the result.

Implementation

Future<RestResponse> execute(RestRequest restRequest) async {

  RestRequestConverter requestConverter = _requestConverterForType(restRequest.requestConverterType);

  RestResponseConverter responseConverter = _responseConverterForType(restRequest.responseConverterType);

  RestRowRequest? rowRequest = requestConverter.toRow(restRequest);

  rowRequest = await _requestMiddleware.next(rowRequest);

  RestRowResponse rowResult = await _restRequestExecutor.execute(rowRequest);

  rowResult = await _responseMiddleware.next(rowResult);

  RestResponse? response = responseConverter.fromRow(rowResult);

  return response;
}