getHttpClient method

  1. @visibleForTesting
AWSHttpClient getHttpClient(
  1. EndpointType type, {
  2. String? apiName,
  3. APIAuthorizationType<AmplifyAuthProvider>? authorizationMode,
})
inherited

Returns the HTTP client to be used for REST/GraphQL operations.

Use apiName if there are multiple endpoints of the same type.

Implementation

@visibleForTesting
AWSHttpClient getHttpClient(
  EndpointType type, {
  String? apiName,
  APIAuthorizationType? authorizationMode,
}) {
  final endpoint = _apiConfig.getEndpoint(
    type: type,
    apiName: apiName,
  );
  final authModeForClientKey =
      authorizationMode ?? endpoint.config.authorizationType;
  final clientPoolKey = '${endpoint.name}.${authModeForClientKey.name}';
  return _clientPool[clientPoolKey] ??= AmplifyHttpClient(
    dependencies,
    baseClient: AmplifyAuthorizationRestClient(
      endpointConfig: endpoint.config,
      baseClient: _options.baseHttpClient ?? dependencies.getOrCreate(),
      authorizationMode: authorizationMode,
      authProviderRepo: _authProviderRepo,
    ),
  );
}