execute method

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

HttpRestClient.execute -> RequestConverter.toRow -> Middleware.next -> RequestExecutor.execute -> Middleware.next -> ResponseConverter.fromRow

Here are the descriptions of each pace in the request execution. HttpRestClient.execute starts the request. RequestConverter.toRow converts the HttpRestRequest to RowRequest. Middleware.next this calls all the request middlewares in the chain. RequestExecutor.execute handle the http request and returns RowResponse. Middleware.next this calls all the response middlewares in the chain. ResponseConverter.fromRow converts the RowRequest to HttpRestRequest. eventually returns the result.

Implementation

Future<HttpRestResponse> execute(HttpRestRequest request) async {

  request = await _requestOverrideMiddleware.next(request);

  RequestConverter requestConverter =
      _requestConverterForType(request.requestConverterType);

  ResponseConverter responseConverter =
      _responseConverterForType(request.responseConverterType);

  RowRequest? rowRequest = requestConverter.toRow(request);

  rowRequest = await _requestMiddleware.next(rowRequest);

  RowResponse rowResult = await _requestExecutor.execute(rowRequest);

  rowResult = await _responseMiddleware.next(rowResult);

  HttpRestResponse? response = responseConverter.fromRow(rowResult);

  return response;
}