Classes · @purista/core

HttpClient

HTTP client with JSON helpers, timeout handling, tracing, metrics, and normalized errors.

Signature

HttpClient.ts typescript
class HttpClient<CustomConfig>

Examples

example-1.ts typescript
const client = new HttpClient({baseUrl: 'http:___PH0___

___PH1___
const result = await client.get('v1/orders&#39;)

Constructors

1 entry

constructor

Constructor

Source
constructor.ts typescript
new constructor<CustomConfig>(config: mapped)

Properties

8 entries

auth

Property

Source
auth.ts typescript
auth: AuthCredentials

baseUrl

Property

Source
baseUrl.ts typescript
baseUrl: URL | undefined

Parsed base URL, when configured.

config

Property

Source
config.ts typescript
config: mapped

Resolved client configuration.

logger

Property

Source
logger.ts typescript
logger: Logger

Logger scoped to this client.

name

Property

Source
name.ts typescript
name: string

Client name used in logs, spans, and metrics.

spanProcessor

Property

Source
spanProcessor.ts typescript
spanProcessor: SpanProcessor | undefined

Optional OpenTelemetry span processor configured for this client.

timeout

Property

Source
timeout.ts typescript
timeout: number

Default request timeout in milliseconds.

traceProvider

Property

Source
traceProvider.ts typescript
traceProvider: NodeTracerProvider

Node tracer provider owned by this client instance.

Methods

10 entries

delete

Method

Source
delete.ts typescript
delete<T>(path: string, options?: HttpClientRequestOptions, payload?: unknown): Promise<T>

DELETE request.

execute

Method

Source
execute.ts typescript
execute(method: string, path: string, options?: HttpClientRequestOptions, payload?: unknown): Promise<any>

Helper method

get

Method

Source
get.ts typescript
get<T>(path: string, options?: HttpClientRequestOptions): Promise<T>

GET request.

getTracer

Method

Source
getTracer.ts typescript
getTracer(): Tracer

Returns OpenTelemetry tracer of this client.

getUrlAndHeader

Method

Source
getUrlAndHeader.ts typescript
getUrlAndHeader(path: string, options?: HttpClientRequestOptions): { headers: Record<string, string>; url: URL }

patch

Method

Source
patch.ts typescript
patch<T>(path: string, payload: unknown, options?: HttpClientRequestOptions): Promise<T>

PATCH request with an optional JSON payload.

post

Method

Source
post.ts typescript
post<T>(path: string, payload: unknown, options?: HttpClientRequestOptions): Promise<T>

POST request with an optional JSON payload.

put

Method

Source
put.ts typescript
put<T>(path: string, payload: unknown, options?: HttpClientRequestOptions): Promise<T>

PUT request with an optional JSON payload.

setBearerToken

Method

Source
setBearerToken.ts typescript
setBearerToken(token: string | undefined): void

Set the bearer token for all following requests.

startActiveSpan

Method

Source
startActiveSpan.ts typescript
startActiveSpan<F>(name: string, opts: SpanOptions, context: Context | undefined, fn: (span: Span) => Promise<F>): Promise<F>

Start a child span for OpenTelemetry tracking.