Skip to content

@yildizpay/http-adapterEnterprise-grade HTTP client for Node.js

Zero-dependency. Fully typed. Battle-tested resilience patterns — built on top of the Native Fetch API.

@yildizpay/http-adapter

See It in Action

typescript
import { HttpAdapter, RetryPolicies } from '@yildizpay/http-adapter';

const adapter = HttpAdapter.builder()
  .withInterceptor(new AuthInterceptor(), new LoggingInterceptor())
  .withRetryPolicy(RetryPolicies.exponential(3))
  .withCircuitBreaker({ failureThreshold: 5, resetTimeoutMs: 30_000 })
  .withCorrelationId()
  .build();
typescript
import { RequestBuilder, HttpMethod } from '@yildizpay/http-adapter';

const request = new RequestBuilder('https://api.payment.com')
  .setEndpoint('/v1/charges')
  .setMethod(HttpMethod.POST)
  .setBody({ amount: 1000, currency: 'USD' })
  .build();
typescript
import {
  TooManyRequestsException,
  CircuitBreakerOpenException,
  NetworkException,
} from '@yildizpay/http-adapter';

try {
  const response = await adapter.send<ChargeResponse>(request);
  console.log('Charge ID:', response.data.id);
} catch (error) {
  if (error instanceof TooManyRequestsException) {
    console.warn(`Rate limited. Retry after ${error.getRetryAfterMs()}ms`);
  } else if (error instanceof CircuitBreakerOpenException) {
    console.error('Payment service unavailable. Failing fast.');
  } else if (error instanceof NetworkException) {
    console.error('Network failure:', error.toJSON());
  }
}
typescript
import { MockHttpAdapter } from '@yildizpay/http-adapter/testing';

const adapter = new MockHttpAdapter();

adapter
  .onEndpoint('/v1/charges')
  .mockResolvedValue({ id: 'ch_123', status: 'succeeded' });

await chargeService.process(order);

adapter.assertCalledWith('/v1/charges', { method: HttpMethod.POST });
adapter.assertCalledTimes(1);

Why @yildizpay/http-adapter?

Built around the real challenges of service-to-service communication in production Node.js applications — not just wrapping fetch.

Raw Fetchaxios@yildizpay/http-adapter
Typed exception per HTTP status code
Built-in Circuit Breaker
Per-request retry/circuit override
Response validation hooks
isRetryable() signal on errors
Structured toJSON() on all errors
First-class testing utilities
Zero production dependencies
Runs on Node.js Native Fetch

Released under the MIT License.