Registry /
http-networking / ngx-forkable-http-client
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ForkableHttpClient
✓ import { ForkableHttpClient } from 'ngx-forkable-http-client';
✗ import { HttpClient as ForkableHttpClient } from '@angular/common/http';
This is the extended HttpClient class you should inject and use for forking. Do not confuse it with Angular's native HttpClient.
httpClient
✓ import { httpClient } from 'ngx-forkable-http-client';
✗ import { httpClient } from '@angular/common/http';
This is a utility factory function used to define ForkableHttpClient instances with specific interceptors within InjectionToken factories. It is not a class.
InjectionToken
✓ import { InjectionToken } from '@angular/core';
While part of Angular core, it's crucial for defining and providing named instances of ForkableHttpClient.
Demonstrates how to define and configure multiple `ForkableHttpClient` instances using `InjectionToken` and the `httpClient` factory, each with its own specific `HttpInterceptor`s, making them root-provided. This sets up distinct HTTP clients for different API needs.
import { InjectionToken, Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
import { Observable } from 'rxjs';
import { ForkableHttpClient, httpClient } from 'ngx-forkable-http-client';
// Dummy Interceptors for demonstration
@Injectable()
export class MyAuthenticationHttpInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
console.log('Auth Interceptor: ', req.url);
const authReq = req.clone({ setHeaders: { Authorization: `Bearer ${process.env.AUTH_TOKEN ?? 'my-secret-token'}` } });
return next.handle(authReq);
}
}
@Injectable()
export class LoggingHttpInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
console.log('Logging Interceptor: ', req.method, req.url);
return next.handle(req);
}
}
@Injectable()
export class ErrorHandlerHttpInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
console.log('Error Handler Interceptor: ', req.url);
return next.handle(req);
}
}
@Injectable()
export class AnotherHttpInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
console.log('Another Interceptor: ', req.url);
return next.handle(req);
}
}
export const MY_REST_API_HTTP_CLIENT =
new InjectionToken<ForkableHttpClient>('MY_REST_API_HTTP_CLIENT', {
providedIn: 'root',
factory: () => httpClient().with(MyAuthenticationHttpInterceptor, LoggingHttpInterceptor)
});
export const EXTERNAL_API_X_HTTP_CLIENT =
new InjectionToken<ForkableHttpClient>('EXTERNAL_API_X_HTTP_CLIENT', {
providedIn: 'root',
factory: () => httpClient().with(ErrorHandlerHttpInterceptor)
});
export const EXTERNAL_API_Y_HTTP_CLIENT =
new InjectionToken<ForkableHttpClient>('EXTERNAL_API_Y_HTTP_CLIENT', {
providedIn: 'root',
factory: () => httpClient().with(AnotherHttpInterceptor)
});
// Example of how to use in a component or service:
// @Component({...})
// export class MyService {
// constructor(@Inject(MY_REST_API_HTTP_CLIENT) private myApiClient: ForkableHttpClient) {
// this.myApiClient.get('/data').subscribe(res => console.log(res));
// }
// }
Errors
Common errors & fixes
Error: NG0201: No provider for InjectionToken MY_REST_API_HTTP_CLIENT!
The `InjectionToken` for your forked `HttpClient` is not correctly provided in the Angular dependency injection system.
fixEnsure your `InjectionToken` specifies `providedIn: 'root'` or that it is explicitly added to the `providers` array of an `@NgModule` where it needs to be available. Example: `new InjectionToken<ForkableHttpClient>(..., { providedIn: 'root', factory: ... });` TypeError: httpClient.fork is not a function
You are attempting to call `fork()` on Angular's native `HttpClient` instead of the extended `ForkableHttpClient` provided by this library.
fixEnsure you are injecting `ForkableHttpClient` from `ngx-forkable-http-client` and not `HttpClient` from `@angular/common/http` when you intend to use the forking functionality. Update your import and injection site.
Argument of type 'typeof MyInterceptor' is not assignable to parameter of type 'HttpInterceptor'.
The class provided to `httpClient().with()` or `ForkableHttpClient.fork()` does not correctly implement the `HttpInterceptor` interface, or it's not marked as `@Injectable()`.
fixVerify that your interceptor class has an `intercept` method with the correct signature (`intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>`) and is decorated with `@Injectable()`.
Audit
Dependencies
@angular/corerequiredCore Angular functionalities, including dependency injection and InjectionToken.
@angular/commonrequiredProvides the base HttpClient and HttpInterceptor interfaces that this library extends.
rxjsrequiredAngular's HttpClient relies heavily on RxJS Observables.