Skip to main content

provideWorkerHttpClient

Angular HttpBackend replacement that routes HttpClient requests to Web Workers off the main thread. Drop-in integration with Angular DI — use WorkerHttpClient just like HttpClient.

TypeScriptexample.ts
import { provideWorkerHttpClient } from '@angular-helpers/worker-http/backend'

# Methods

MethodSignatureReturnsDescription
provideWorkerHttpClientprovideWorkerHttpClient(...features: WorkerHttpFeature[]): EnvironmentProvidersEnvironmentProvidersRoot provider that replaces provideHttpClient(). Registers WorkerHttpBackend, WorkerHttpClient, and all feature providers.
withWorkerConfigswithWorkerConfigs(configs: WorkerConfig[]): WorkerHttpFeatureWorkerHttpFeature<"WorkerConfigs">Registers named worker definitions. Each WorkerConfig has id, workerUrl, and optional maxInstances for pooling.
withWorkerRouteswithWorkerRoutes(routes: WorkerRoute[]): WorkerHttpFeatureWorkerHttpFeature<"WorkerRoutes">URL-pattern to worker routing rules. Higher priority = evaluated first. Patterns can be RegExp or string prefix.
withWorkerFallbackwithWorkerFallback(strategy: 'main-thread' | 'error'): WorkerHttpFeatureWorkerHttpFeature<"WorkerFallback">Configures behavior when workers are unavailable (SSR, unsupported browsers). 'main-thread' uses FetchBackend; 'error' throws.
withWorkerSerializationwithWorkerSerialization(serializer: WorkerSerializer): WorkerHttpFeatureWorkerHttpFeature<"WorkerSerialization">Plugs in a custom serializer for request body crossing the worker boundary. Use with createSerovalSerializer() for complex types (Date, Map, Set).
WorkerHttpClient.get / post / put / delete / patchget<T>(url, options?: WorkerRequestOptions): Observable<T>Observable<T>HttpClient-compatible methods with an optional { worker: string } field for per-request worker routing.
LCP N/A
CLS N/A
INP N/A