İstek Bazlı Geçersiz Kılma
Adapter'ın global yapılandırması (retry politikası, circuit breaker, interceptor'lar) varsayılan olarak her isteğe uygulanır. Tek bir isteğin farklı davranışa ihtiyaç duyduğu durumlarda, RequestBuilder diğer hiçbir isteği etkilemeden global yapılandırmanın tam önüne geçen istek bazlı geçersiz kılmalar sunar.
Retry Politikası
import { RetryPolicies } from '@yildizpay/http-adapter';
// Geçersiz kıl: bu istek için belirli bir politika kullan
const kritikIstek = new RequestBuilder('https://api.example.com')
.setEndpoint('/v1/payments')
.withRetryPolicy(RetryPolicies.decorrelatedJitter(5))
.build();
// Devre dışı bırak: global politikadan bağımsız olarak bu istek için retry yok
const hassasIstek = new RequestBuilder('https://api.example.com')
.setEndpoint('/v1/refunds')
.withoutRetry()
.build();withoutRetry() ne zaman kullanılır?
Retry durumunda yinelenen yan etkilere neden olabilecek idempotent olmayan işlemler için kullanın (örneğin ödeme oluşturma, bildirim gönderme). Yeniden denenen bir POST'ta yinelenen ödeme, başarısız bir istekten çok daha kötüdür.
Circuit Breaker
// Geçersiz kıl: bu endpoint için özel bir circuit breaker instance'ı kullan
const request = new RequestBuilder('https://api.example.com')
.setEndpoint('/v1/payments')
.withCircuitBreaker(new CircuitBreaker({ failureThreshold: 3, resetTimeoutMs: 15_000 }))
.build();
// Atla: bu istek için circuit breaker'ı tamamen devre dışı bırak
const saglikProbu = new RequestBuilder('https://api.example.com')
.setEndpoint('/health')
.withoutCircuitBreaker()
.build();withoutCircuitBreaker() ne zaman kullanılır?
Servisin çalışıp çalışmadığını gerçekten öğrenmek istediğiniz health check veya readiness probe endpoint'leri için kullanın — önbelleğe alınmış bir CircuitBreakerOpenException değil.
Interceptor Hariç Tutma
Sınıfa Göre Hariç Tutma
Bir interceptor sınıfının tüm instance'larını bu isteğin pipeline'ından kaldırır:
// Hassas yanıt için loglamayı atla (örn. yanıt KKB içeriyor)
const hassasIstek = new RequestBuilder('https://api.example.com')
.setEndpoint('/v1/users/profile')
.withoutInterceptor(LoggingInterceptor)
.build();Instance'a Göre Hariç Tutma
Aynı interceptor sınıfının birden fazla instance'ı farklı yapılandırmalarla kayıtlıyken kullanışlıdır:
const odemeLogger = new LoggingInterceptor('payments');
const genelLogger = new LoggingInterceptor('general');
const adapter = HttpAdapter.builder()
.withInterceptor(odemeLogger, genelLogger)
.build();
// Bu istek için yalnızca ödeme logger'ını atla
const request = new RequestBuilder('https://api.example.com')
.setEndpoint('/v1/internal')
.withoutInterceptorInstance(odemeLogger)
.build();Geçersiz Kılmaları Birleştirme
Tüm geçersiz kılmalar tek bir istek üzerinde birleştirilebilir:
const kritikIstek = new RequestBuilder('https://api.example.com')
.setEndpoint('/v1/kritik-islem')
.setMethod(HttpMethod.POST)
.setBody(payload)
.withRetryPolicy(RetryPolicies.exponential(5))
.withCircuitBreaker(new CircuitBreaker({ failureThreshold: 2, resetTimeoutMs: 10_000 }))
.withoutInterceptor(LoggingInterceptor)
.withCorrelationId('x-kritik-trace-id')
.build();