const BASE = 'https://omdaa.com/api/v1';
async function omdaaGet(path, token, { retries = 2 } = {}) {
for (let i = 0; i <= retries; i++) {
const res = await fetch(BASE + path, {
headers: { Authorization: `Bearer ${token}`, Accept: 'application/json' },
});
if (res.status === 429 || res.status >= 500) {
await new Promise((r) => setTimeout(r, 500 * (i + 1)));
continue;
}
if (!res.ok) throw new Error(await res.text());
return res.json();
}
}
ملاحظات
- لا تضع التوكن في frontend عام
- استخدم workers أو backend خاص بك
- راقب
x-ratelimit-* إن وُجدت