AngularBackend
Angular-specific HttpBackend implementation. Delegates all HTTP traffic to Angular's own HttpClient instead of the browser fetch API, so Angular's interceptor chain, HttpContext, and DI system remain fully active.
OpraClientModule.registerClient() wires AngularBackend automatically. Use this class directly only when you are constructing a client manually.
Class
class AngularBackend extends HttpBackend
Constructor
new AngularBackend(
httpClient: HttpClient,
serviceUrl: string,
options?: AngularBackend.Options,
)
| Parameter | Type | Description |
|---|---|---|
httpClient | HttpClient | Angular's injected HttpClient |
serviceUrl | string | Base URL of the OPRA service |
options | AngularBackend.Options | Optional defaults and interceptors |
Properties
| Property | Type | Description |
|---|---|---|
httpClient | HttpClient | The Angular HttpClient instance |
serviceUrl | string | Normalized base URL |
defaults | AngularBackend.RequestDefaults | Default headers and query params merged into every request |
Protected methods
Override these to customize behavior without reimplementing the full transport.
| Method | Description |
|---|---|
send(request) | Calls httpClient.request(request) — override to intercept at the lowest level |
prepareRequest(init) | Applies defaults, normalizes the URL, serializes the body |
createResponse(init) | Constructs the HttpResponse instance |
Usage
// api-client.token.ts
export const API_CLIENT = new InjectionToken<OpraAngularClient>('API_CLIENT');
// app.module.ts
@NgModule({
imports: [
OpraClientModule.registerClient({
serviceUrl: 'https://api.example.com',
token: API_CLIENT,
defaults: {
headers: new Headers({ Authorization: 'Bearer token' }),
},
}),
],
})
export class AppModule {}
// orders.service.ts
@Injectable({ providedIn: 'root' })
export class OrdersService {
constructor(@Inject(API_CLIENT) private client: OpraAngularClient) {}
getOrders() {
return this.client.get<Order[]>('orders').getBody();
}
createOrder(input: Order) {
return this.client.post<Order>('orders', input).getBody();
}
}
Interfaces
AngularBackend.Options
interface Options extends HttpBackend.Options {
defaults?: RequestDefaults;
}
AngularBackend.RequestInit
Extends HttpBackend.RequestInit with Angular-specific fields.
interface RequestInit extends HttpBackend.RequestInit {
context?: HttpContext;
reportProgress?: boolean;
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
}
AngularBackend.RequestOptions
Subset exposed as per-request options via .options() on HttpRequestObservable.
interface RequestOptions {
context?: HttpContext;
reportProgress?: boolean;
withCredentials?: boolean;
}
AngularBackend.RequestDefaults
type RequestDefaults = {
headers: Headers;
params: URLSearchParams;
reportProgress?: boolean;
withCredentials?: boolean;
}
See also
OpraClientModule— Angular module that wiresAngularBackendvia DIHttpBackend— abstract base class