Classes · @purista/core
HttpClient
HTTP client with JSON helpers, timeout handling, tracing, metrics, and normalized errors.
Signature
class HttpClient<CustomConfig> Examples
const client = new HttpClient({baseUrl: 'http:___PH0___
___PH1___
const result = await client.get('v1/orders39;) Constructors
1 entry
constructor
Constructor
new constructor<CustomConfig>(config: mapped) Properties
8 entries
auth
Property
auth: AuthCredentials baseUrl
Property
baseUrl: URL | undefined Parsed base URL, when configured.
config
Property
config: mapped Resolved client configuration.
logger
Property
logger: Logger Logger scoped to this client.
name
Property
name: string Client name used in logs, spans, and metrics.
spanProcessor
Property
spanProcessor: SpanProcessor | undefined Optional OpenTelemetry span processor configured for this client.
timeout
Property
timeout: number Default request timeout in milliseconds.
traceProvider
Property
traceProvider: NodeTracerProvider Node tracer provider owned by this client instance.
Methods
10 entries
delete
Method
delete<T>(path: string, options?: HttpClientRequestOptions, payload?: unknown): Promise<T> DELETE request.
execute
Method
execute(method: string, path: string, options?: HttpClientRequestOptions, payload?: unknown): Promise<any> Helper method
get
Method
get<T>(path: string, options?: HttpClientRequestOptions): Promise<T> GET request.
getTracer
Method
getTracer(): Tracer Returns OpenTelemetry tracer of this client.
getUrlAndHeader
Method
getUrlAndHeader(path: string, options?: HttpClientRequestOptions): { headers: Record<string, string>; url: URL } patch
Method
patch<T>(path: string, payload: unknown, options?: HttpClientRequestOptions): Promise<T> PATCH request with an optional JSON payload.
post
Method
post<T>(path: string, payload: unknown, options?: HttpClientRequestOptions): Promise<T> POST request with an optional JSON payload.
put
Method
put<T>(path: string, payload: unknown, options?: HttpClientRequestOptions): Promise<T> PUT request with an optional JSON payload.
setBearerToken
Method
setBearerToken(token: string | undefined): void Set the bearer token for all following requests.
startActiveSpan
Method
startActiveSpan<F>(name: string, opts: SpanOptions, context: Context | undefined, fn: (span: Span) => Promise<F>): Promise<F> Start a child span for OpenTelemetry tracking.