Skip to main content

HttpClientBase

Abstract base class for all OPRA HTTP clients. Provides the full request API — HTTP verb methods, fetchDocument, and the pluggable backend slot.

OpraHttpClient and HttpFetchClient both extend HttpClientBase. Extend it directly only when you need to inject a custom backend (non-fetch transport).

import { HttpClientBase, HttpBackend } from '@opra/client';

class MockClient extends HttpClientBase {
constructor() {
super(new MockBackend('http://localhost'));
}
}

Constructor

protected constructor(backend: HttpBackend)

The backend is stored internally and used for all requests. Swap it to change the transport layer entirely — the rest of the client is unchanged.


Properties

PropertyTypeDescription
serviceUrlstringBase URL from the backend (trailing slash normalized)

Methods

request<TBody>(path, options?)

Creates a lazy HttpRequestObservable. No request is sent until you subscribe or call .getBody() / .getResponse().

request<TBody = any>(
path: string,
options?: OpraClientBase.RequestOptions,
): HttpRequestObservable<TBody, TBody, TRequestOptions, TResponseExt>

get<TBody>(path, options?)

get<TBody = any>(
path: string,
options?: Omit<OpraClientBase.RequestOptions, 'method' | 'body'>,
): HttpRequestObservable<TBody, ...>

post<TBody>(path, body, options?)

post<TBody = any>(path: string, body: any, options?): HttpRequestObservable<TBody, ...>

patch<TBody>(path, body, options?)

patch<TBody = any>(path: string, body: any, options?): HttpRequestObservable<TBody, ...>

put<TBody>(path, body, options?)

put<TBody = any>(path: string, body: any, options?): HttpRequestObservable<TBody, ...>

delete<TBody>(path, options?)

delete<TBody = any>(
path: string,
options?: Omit<OpraClientBase.RequestOptions, 'method' | 'body'>,
): HttpRequestObservable<TBody, ...>

fetchDocument(options?)

Fetches the OPRA API schema from $schema on the service and returns a parsed ApiDocument. Resolves referenced sub-documents recursively.

fetchDocument(options?: { documentId?: string }): Promise<ApiDocument>

Interfaces

OpraClientBase.RequestOptions

type RequestOptions = Partial<Omit<HttpBackend.RequestInit, 'url'>> & {
params?: URLSearchParamsInit;
};

See also