code: def _generate_api_config_with_root(self, request):
      
      actual_root = self._get_actual_root(request)
      generator = api_config.ApiConfigGenerator()
      api = request.body_json['api']
      version = request.body_json['version']
      lookup_key = (api, version)
  
      service_factories = self._backend.api_name_version_map.get(lookup_key)
      if not service_factories:
        return None
  
      service_classes = [service_factory.service_class
                         for service_factory in service_factories]
      config_dict = generator.get_config_dict(
          service_classes, hostname=actual_root)
  
      # Save to cache
      for config in config_dict.get('items', []):
        lookup_key_with_root = (
            config.get('name', ''), config.get('version', ''), actual_root)
        self._config_manager.save_config(lookup_key_with_root, config)
  
      return config_dict
docs: Generate an API config with a specific root hostname.
  
      This uses the backend object and the ApiConfigGenerator to create an API
      config specific to the hostname of the incoming request. This allows for
      flexible API configs for non-standard environments, such as localhost.
  
      Args:
        request: An ApiRequest, the transformed request sent to the Discovery API.
  
      Returns:
        A string representation of the generated API config.