Proje: Okul B2B App · Hub: Okul B2B App — Conventions

ApiClient GET Cache ve Deduplication

Cache Sistemi

GET istekleri varsayılan olarak cache’lenir (useCache: true):

apiClient.get('/customer/leads', { useCache: true });  // Cache aktif (default)
apiClient.get('/customer/leads', { useCache: false }); // Cache bypass

Cache key: URL + headers kombinasyonu TTL: 5 dakika

Request Deduplication

Aynı anda aynı URL’e birden fazla istek geldiğinde sadece bir HTTP isteği yapılır:

// pendingRequests Map'i
const pendingRequest = this.pendingRequests.get(cacheKey);
if (pendingRequest) {
  return pendingRequest; // Aynı sonucu bekle
}

Cache miss olduğunda pending request Map’e eklenir. Response gelince hem cache’e yazılır hem pending’den kaldırılır.

postPublic vs post

// Public endpoint (auth gerektirmez): X-API-Key header eklenir
apiClient.postPublic('/auth/login', body);
 
// Private endpoint (auth gerektirir): Authorization: Bearer header eklenir
apiClient.post('/customer/leads', body);

PUBLIC_HEADERS ve DEFAULT_HEADERS ayrı — public’te API Key, private’de JWT token.