requestHttpClient method

  1. @override
Future<HttpResponse> requestHttpClient(
  1. HttpClient client,
  2. HttpMethod method,
  3. String path,
  4. bool fullPath,
  5. Map? parameters,
  6. Object? body,
)
override

Method responsible to request the HttpClient.

Can be overwritten by other implementations.

Implementation

@override
Future<HttpResponse> requestHttpClient(HttpClient client, HttpMethod method,
    String path, bool fullPath, Map? parameters, body) {
  if (parametersPattern != null && parametersPattern!.isNotEmpty) {
    parameters ??= {};
    var queryParameters = HttpCall.toQueryParameters(parameters);
    for (var entry in parametersPattern!.entries) {
      var k = _resolvePattern(entry.key, queryParameters);
      var v = _resolvePattern(entry.value, queryParameters);
      parameters[k] = v;
    }
  }

  if (parameters != null) {
    var findByID = parameters.remove('--id');
    if (findByID != null) {
      path = _appendPath(path, findByID);
      parameters = HttpCall.toQueryParameters(parameters);
    } else {
      var findFromID = parameters.remove('--fromID');
      var findToID = parameters.remove('--toID');

      if (findFromID != null && findToID != null) {
        path = _appendPath(path, '$findFromID..$findToID');
        parameters = HttpCall.toQueryParameters(parameters);
      } else {
        var filter = parameters.remove('--filter');
        if (filter != null && filter is Map) {
          parameters = HttpCall.toQueryParameters(filter);
        } else {
          parameters = HttpCall.toQueryParameters(parameters);
        }
      }
    }
  }

  return super
      .requestHttpClient(client, method, path, fullPath, parameters, body);
}