DocsAPI ReferenceprovideStreamResource()

provideStreamResource()

provideStreamResource is the provider factory that registers stream-resource in Angular's dependency injection system. Call it once inside bootstrapApplication (or an ApplicationConfig) to configure the transport and any global defaults used by every streamResource in your app.

This is the single configuration point for the entire library. Rather than configuring each resource individually, you declare your transport here and every streamResource call throughout the app inherits it automatically.

import { bootstrapApplication } from '@angular/platform-browser';
import {
  provideStreamResource,
  FetchStreamTransport,
} from '@cacheplane/stream-resource';
import { AppComponent } from './app/app.component';
 
bootstrapApplication(AppComponent, {
  providers: [
    provideStreamResource({
      transport: FetchStreamTransport,
    }),
  ],
});

Global configuration

| Option | Type | Description | |--------|------|-------------| | transport | Type<StreamTransport> | The transport class to inject when resources request StreamTransport. Required. |

Swapping transports by environment

Because provideStreamResource accepts a class token, you can vary the transport based on your environment without touching any component code:

// main.ts — production
provideStreamResource({ transport: FetchStreamTransport })
 
// main.spec.ts / TestBed — tests
provideStreamResource({ transport: MockStreamTransport })
One provider, any transport

Swap FetchStreamTransport for MockStreamTransport (or any custom class implementing the StreamTransport interface) to change the transport for all resources at once — useful for testing or SSR.

What's Next

provideStreamResourcefunction

Angular provider factory that registers global defaults for all streamResource instances in the application. Add to your `app.config.ts` or module providers array.

provideStreamResource(config: StreamResourceConfig): Provider

Parameters

ParameterTypeDescription
configStreamResourceConfigGlobal configuration merged with per-call options

Returns

Provider

Examples

// app.config.ts
export const appConfig: ApplicationConfig = {
  providers: [
    provideStreamResource({ apiUrl: 'http://localhost:2024' }),
  ],
};