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
| Method | Signature | Returns | Description |
|---|---|---|---|
provideWorkerHttpClient | provideWorkerHttpClient(...features: WorkerHttpFeature[]): EnvironmentProviders | EnvironmentProviders | Root provider that replaces provideHttpClient(). Registers WorkerHttpBackend, WorkerHttpClient, and all feature providers. |
withWorkerConfigs | withWorkerConfigs(configs: WorkerConfig[]): WorkerHttpFeature | WorkerHttpFeature<"WorkerConfigs"> | Registers named worker definitions. Each WorkerConfig has id, workerUrl, and optional maxInstances for pooling. |
withWorkerRoutes | withWorkerRoutes(routes: WorkerRoute[]): WorkerHttpFeature | WorkerHttpFeature<"WorkerRoutes"> | URL-pattern to worker routing rules. Higher priority = evaluated first. Patterns can be RegExp or string prefix. |
withWorkerFallback | withWorkerFallback(strategy: 'main-thread' | 'error'): WorkerHttpFeature | WorkerHttpFeature<"WorkerFallback"> | Configures behavior when workers are unavailable (SSR, unsupported browsers). 'main-thread' uses FetchBackend; 'error' throws. |
withWorkerSerialization | withWorkerSerialization(serializer: WorkerSerializer): WorkerHttpFeature | WorkerHttpFeature<"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 / patch | get<T>(url, options?: WorkerRequestOptions): Observable<T> | Observable<T> | HttpClient-compatible methods with an optional { worker: string } field for per-request worker routing. |