constructRequest method

Future<Response> constructRequest(
  1. Dio client,
  2. RequestMethod method,
  3. dynamic encodedData
)

Executes the appropriate HTTP verb using named queryParameters and per-request dio.Options. Headers and timeouts travel with the call rather than being stamped onto the shared client.

Implementation

Future<dio.Response> constructRequest(
  dio.Dio client,
  RequestMethod method,
  dynamic encodedData,
) async {
  cancelToken = dio.CancelToken();

  final options = _buildRequestOptions();
  final queryParams = (query?.isNotEmpty ?? false) ? query : null;
  final path = (baseUrl ?? defaultSettings.defaultBaseUrl) + (url ?? '');

  decorateRequest(client, options);

  switch (method) {
    case .get:
      return client.get(
        path,
        queryParameters: queryParams,
        options: options,
        cancelToken: cancelToken,
      );
    case .post:
      return client.post(
        path,
        data: encodedData,
        queryParameters: queryParams,
        options: options,
        cancelToken: cancelToken,
      );
    case .put:
      return client.put(
        path,
        data: encodedData,
        queryParameters: queryParams,
        options: options,
        cancelToken: cancelToken,
      );
    case .delete:
      return client.delete(
        path,
        data: encodedData,
        queryParameters: queryParams,
        options: options,
        cancelToken: cancelToken,
      );
    case .patch:
      return client.patch(
        path,
        data: encodedData,
        queryParameters: queryParams,
        options: options,
        cancelToken: cancelToken,
      );
  }
}