@temboplus/wire
v0.0.9
Published
A lightweight HTTP client for service-to-service communication in Node.js microservices. Uses the Result pattern — never throws, always returns a typed `WireResult<T>`.
Readme
@temboplus/wire
A lightweight HTTP client for service-to-service communication in Node.js microservices. Uses the Result pattern — never throws, always returns a typed WireResult<T>.
Installation
npm install @temboplus/wireUsage
import { Wire, WireStatus } from '@temboplus/wire';
const wire = new Wire({
defaultHeaders: { Authorization: 'Bearer token' },
});
const result = await wire.get<User>('https://api.example.com/users/1');
if (result.status === WireStatus.SUCCESS) {
console.log(result.data);
} else {
console.error(result.error);
}API
new Wire(config?)
| Option | Type | Description |
|---|---|---|
| defaultHeaders | Record<string, string> | Headers included on every request |
Methods
All methods return Promise<WireResult<T>> and never throw.
wire.get<T>(url, options?)
wire.post<T>(url, body?, options?)
wire.put<T>(url, body?, options?)
wire.patch<T>(url, body?, options?)
wire.delete<T>(url, options?)WireOptions:
| Option | Type | Description |
|---|---|---|
| headers | Record<string, string> | Per-request headers, merged with defaultHeaders |
WireResult<T>
interface WireResult<T> {
status: WireStatus;
statusCode: number; // 0 when REQUEST_FAILED
data?: T;
error?: WireError;
}WireStatus
| Value | Condition |
|---|---|
| SUCCESS | 2xx response |
| INVALID_REQUEST | 4xx response |
| SERVICE_ERROR | 5xx response, or 2xx/4xx with invalid JSON |
| REQUEST_FAILED | No response received (network error, invalid URL, etc.) |
WireError
interface WireError {
code?: string; // e.g. 'INVALID_JSON', 'ECONNREFUSED'
message: string;
cause?: unknown;
}