execute method

Future<ApexResponse> execute(
  1. ApexRequest restRequest
)

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

ApexClient.execute -> RequestConverter.toRow -> Middleware.next -> RestRequestExecutor.execute -> Middleware.next -> ResponseConverter.fromRow

Here are the descriptions of each pace in the request execution. ApexClient.execute starts the request. RequestConverter.toRow converts the ApexRequest to RowRequest. Middleware.next this calls all the request middlewares in the chain. RestRequestExecutor.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 ApexRequest. eventually returns the result.

Implementation

Future<ApexResponse> execute(ApexRequest restRequest) async {

  RequestConverter requestConverter = _requestConverterForType(restRequest.requestConverterType);

  ResponseConverter responseConverter = _responseConverterForType(restRequest.responseConverterType);

  RowRequest? rowRequest = requestConverter.toRow(restRequest);

  rowRequest = await _requestMiddleware.next(rowRequest);

  RowResponse rowResult = await _restRequestExecutor.execute(rowRequest);

  rowResult = await _responseMiddleware.next(rowResult);

  ApexResponse? response = responseConverter.fromRow(rowResult);

  return response;
}