Proje: Okul B2B App · Hub: Okul B2B App — Conventions
API Client Pattern
Doğru Client: utils/ApiClient.ts
import { apiClient } from '@/utils/ApiClient';
// GET isteği (cache'li)
const response = await apiClient.get<MyType>('/customer/leads', { useCache: true });
// POST isteği (public - auth gerektirmez)
const response = await apiClient.postPublic<LoginResponse>('/auth/login', body);
// POST isteği (auth gerektirir)
const response = await apiClient.post<MyType>('/customer/leads', body);
// Auth token set et (login sonrası)
apiClient.setAuthToken(token);
// Customer ID set et (firma seçimi sonrası)
apiClient.setCustomerId(customerId);Yanlış Kullanım
services/ApiService.ts KULLANMA — bu simüle edilmiş bir mock client. Production’da gerçek HTTP isteği atmaz.
services/SecureApiClient.ts da kullanılmıyor — utils/ApiClient.ts tercih edilir.
Otomatik Header’lar
Her istekte ApiClient otomatik şu header’ları ekler:
Content-Type: application/jsonAccept: application/jsonAccept-Language: trx-consumer-key: CueoknUqTMbqtT99jNoutfs1(production) /customer(DEV)Authorization: Bearer {token}(setAuthToken sonrası)x-cid: {customerId}(setCustomerId sonrası)
Cache Davranışı
- GET istekleri 5 dakika TTL ile cache’lenir
{ useCache: false }veyabypassCache: trueile atlanır- Cache key:
url + headers - Max 100 cache entry (LRU değil, FIFO)
Retry/Timeout
- Default timeout: 30 saniye
- Default retry: 3 deneme
- Exponential backoff:
2^(attempt-1) * 1000ms - 401 aldığında token refresh denenip tekrar istek atılır
URL Yapısı
Expo Go: https://api.okul.work
Production: https://api.okul.com.tr
Config.IS_LEGACY_BUILD flag’i ile api.okul.work kullanan eski build’lar tespit edilir ve zorla logout yapılır.
Related
- error-handling-pattern — API hata yönetimi
- auth-token-yonetimi — token lifecycle