Battle-proven HTTP client for communication between microservices.
Built for production service-to-service traffic: contextual authentication, correlation ID propagation, connection pooling, and automatic recovery from transient network failures.
npm install eh-api-clientconst ClientFactory = require("eh-api-client");
const users = new ClientFactory("http://users-service/v1");
const client = users.getClient(42, "orders-service");
const user = await client.get(["/users/??", 42]);
await client.patch(["/users/??", 42], { active: true });Every method supports both Promises and Node-style callbacks. Available methods are get, post, put, patch, delete, head, and exists.
Propagate x-request-id automatically across asynchronous call chains with AsyncLocalStorage:
const { AsyncLocalStorage } = require("async_hooks");
const ClientFactory = require("eh-api-client");
const requestContext = new AsyncLocalStorage();
ClientFactory.setAsyncLocalStorage(requestContext);
requestContext.run(new Map([["requestId", "req-123"]]), async () => {
await client.get("/profile"); // sends x-request-id: req-123
});Request, session, and device IDs can also be assigned directly with setRequestId, setSessionId, and setDeviceId.
Transient network failures are retried automatically for GET requests. Retries are bounded and configurable:
users.setRetryOptions({
maxAttempts: 5,
retryDelay: 100
});For safe-to-retry writes, set retryOnTransientError: true. Stream bodies are never retried.
- Shared keep-alive connection pool
- Internal, bearer-token, and secret-based authentication
- URL placeholders with safe value encoding
- Forked clients for nested API paths
- Request modifiers and configurable defaults
- Structured HTTP and network errors
request-doneandnetwork-errorlifecycle events- TypeScript declarations included
See the test suite for focused examples of each feature.
ISC
