Angular 4 http batch requests


To optimize my API calls, I would like to make batch requests using this module
As per the example, the configuration is set in AppModule.

export function httpBatchConfigurationFactory() {
  return new HttpBatchConfigurationCollection([
    new HttpBatchConfiguration({
      rootEndpointUrl: "",
      batchEndpointUrl: "$batch"

And in the providers, I have set

{ provide: HttpBatchConfigurationCollection, useFactory: httpBatchConfigurationFactory },
    { provide: Http, useClass: HttpBatcher }

Everything works fine, when this configuration is static.
My application identifies the rootEnPointUrl, only after the user has logged into the application.

How can I add a new HttpBatchConfiguration to this HttpBatchConfigurationCollection, after user authentication?


Why not use an injectable service instead of providing a factory during module setup? So that you can change configuration whenever you like even after app initialised.

Answered By – Xinan

Answer Checked By – Mildred Charles (AngularFixing Admin)

Leave a Reply

Your email address will not be published.