# HttpClient API

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

---
Canonical: /handbook/api/classes/_purista_core.HttpClient/
Source: HttpClient/HttpClient.impl.ts
Format: Markdown for agents
---

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

Package: `@purista/core`

## Signature

```typescript
class HttpClient<CustomConfig>
```

## Examples

```typescript
const client = new HttpClient({baseUrl: 'http://localhost/api})

// GET http://localhost/api/v1/orders
const result = await client.get('v1/orders')
```

## Members

### Constructors

- `new constructor<CustomConfig>(config: mapped)`

### Properties

- `auth: AuthCredentials`
- `baseUrl: URL | undefined` — Parsed base URL, when configured.
- `config: mapped` — Resolved client configuration.
- `logger: Logger` — Logger scoped to this client.
- `name: string` — Client name used in logs, spans, and metrics.
- `spanProcessor: SpanProcessor | undefined` — Optional OpenTelemetry span processor configured for this client.
- `timeout: number` — Default request timeout in milliseconds.
- `traceProvider: NodeTracerProvider` — Node tracer provider owned by this client instance.

### Methods

- `delete<T>(path: string, options?: HttpClientRequestOptions, payload?: unknown): Promise<T>` — DELETE request.
- `execute(method: string, path: string, options?: HttpClientRequestOptions, payload?: unknown): Promise<any>` — Helper method
- `get<T>(path: string, options?: HttpClientRequestOptions): Promise<T>` — GET request.
- `getTracer(): Tracer` — Returns OpenTelemetry tracer of this client.
- `getUrlAndHeader(path: string, options?: HttpClientRequestOptions): { headers: Record<string, string>; url: URL }`
- `patch<T>(path: string, payload: unknown, options?: HttpClientRequestOptions): Promise<T>` — PATCH request with an optional JSON payload.
- `post<T>(path: string, payload: unknown, options?: HttpClientRequestOptions): Promise<T>` — POST request with an optional JSON payload.
- `put<T>(path: string, payload: unknown, options?: HttpClientRequestOptions): Promise<T>` — PUT request with an optional JSON payload.
- `setBearerToken(token: string | undefined): void` — Set the bearer token for all following requests.
- `startActiveSpan<F>(name: string, opts: SpanOptions, context: Context | undefined, fn: (span: Span) => Promise<F>): Promise<F>` — Start a child span for OpenTelemetry tracking.
