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-clientconstClientFactory=require("eh-api-client");constusers=newClientFactory("http://users-service/v1");constclient=users.getClient(42,"orders-service");constuser=awaitclient.get(["/users/??",42]);awaitclient.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");constClientFactory=require("eh-api-client");constrequestContext=newAsyncLocalStorage();ClientFactory.setAsyncLocalStorage(requestContext);requestContext.run(newMap([["requestId","req-123"]]),async()=>{awaitclient.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
