نقل عبر fetch فقط
مسار واحد فوق fetch القياسي — Node وBun وDeno والـ Workers والمتصفات الحديثة دون مكملات إلزامية.
معترضات، وسيط، JSON بمخطط Standard Schema، خطافات دورة إعادة المحاولة، وتخزين مؤقت — fetch فقط لـ Node 18+ والمتصفحات والحافة.
Open in your assistant
Pre-fills a prompt that points at the docs site and . If the message box is empty, paste the prompt from the address bar or type it manually — URL prefill behavior depends on the product.
أبرز ما في openFetch الآن: التحقق من JSON عبر Standard Schema (jsonSchema و**.json(schema)** في الـ fluent)، throwHttpErrors بأسلوب Ky مع validateStatus, تمرير Request الأصلي إلى request()، مصفوفة init[] متزامنة على الإعداد المدمج، ERR_TIMEOUT منفصل عن إلغاء المستخدم، خطافات إعادة المحاولة onAfterResponse / onBeforeRetry مع OpenFetchForceRetry, Accept مقترح من responseType, وtype guards (isHTTPError، isTimeoutError، isSchemaValidationError). قائمة الميزات ومسار الطلب الكامل ←
| المعيار | openFetchمكتبتك | Axios | ky |
|---|---|---|---|
| طبقة النقل | openFetchfetch | AxiosXHR (افتراضي في المتصفح) | kyfetch |
| تبعيات وقت التشغيل | openFetchصفر | Axiosمجموعة خاصة | kyصفر |
| HTTP/2 على Node أو dispatcher | openFetch اختياري: undici من المستخدم؛ `dispatcher` / `allowH2` | Axiosمحولات Node | ky اختياري: undici (التوثيق) |
| مثيل وإعدادات افتراضية | openFetch createClient | Axios axios.create | ky ky.create |
| معترضات الطلب والاستجابة | openFetch الاثنان | Axios الاثنان | ky خطافات فقط |
| وسيط قابل للتجميع | openFetch use() | Axios— | ky— |
| تحويل الطلب / تحويل الاستجابة | openFetch مصفوفات مرتبة في الإعداد | Axios سلسلة تحويل مدمجة | ky خطافات (لا مصفوفات) |
| JSON مُتحقق (Standard Schema) | openFetch jsonSchema وـ .json(schema) | Axios يدوي (مثلاً في transform) | ky .json(schema) |
| بوابة حالة HTTP | openFetch validateStatus و throwHttpErrors | Axios validateStatus | ky throwHttpErrors |
| Request أصلي + init متزامن | openFetch request(Request) + init[] | Axios عبر الإعداد (لا init[]) | ky Request وخطافات init |
| إعادة محاولة مع تراجع (اختياري) | openFetch إضافات + onAfterResponse / ForceRetry | Axios منفصل | ky Retry وخطاف بعد الاستجابة |
| تخزين مؤقت للذاكرة (TTL / SWR) | openFetch createCacheMiddleware ومخزن | Axios طرف ثالث أو يدوي | ky— |
| استجابة موحّدة للعميل | openFetch OpenFetchResponse | Axios AxiosResponse | ky Response / مُحلّى |
| أخطاء، سجلات آمنة، حماية URL | openFetch toShape، إخفاء query، قناع رؤوس، حماية URL | Axios AxiosError؛ إخفاء يدوي | ky أخطاء مُنمّاة؛ إخفاء يدوي |
| مهلة مقابل إلغاء المستخدم | openFetch ERR_TIMEOUT و ERR_CANCELED | Axios غالباً AbortError للاثنين | ky TimeoutError و AbortError |
| عميل متسلسل + memo | openFetch createFluentClient و .memo() | Axios— | ky تسلسل أصلي (لا memo مدمج) |
| مفتاح Idempotency لإعادة POST | openFetch ترويسة تلقائية اختيارية | Axios يدوي أو معترضات | ky يدوي |
| مناسب للحافة و RSC | openFetch يستخدم fetch | Axios محوّلات | ky fetch |
الحجم يعتمد على الدمج والاستيراد. openFetch يضيف طبقة عملية فوق fetch: مخطط JSON، بوابة حالات، Request وinit، وإعادة محاولة مع خطافات — راجع صفحة «الميزات ومسار الطلب» للتفاصيل.
واجهة فئات EscuelaJS تُرجع مصفوفة JSON. أدناه: openFetch، Axios، وky.
openFetch — إعدادات مشتركة، استجابة منظمة، وجاهزية للمعترضات والوسيط:
import openFetch from "@hamdymohamedak/openfetch";
const res = await openFetch.get(
"https://api.escuelajs.co/api/v1/categories"
);
// res.data, res.status, res.headers, res.configAxios — واجهة مألوفة؛ نقل افتراضي مختلف في المتصفح:
import axios from "axios";
const res = await axios.get(
"https://api.escuelajs.co/api/v1/categories"
);
// res.data, res.status, res.headers, res.configky — واجهة صغيرة فوق fetch:
import ky from "ky";
const data = await ky
.get("https://api.escuelajs.co/api/v1/categories")
.json();اضغط تشغيل القياس (٥ جولات): في كل جولة يُنفَّذ ثلاثة طلبات GET متوازية (openFetch، Axios، ky) مع تعطيل التخزين المؤقت حيثما أمكن. البطاقات تعرض آخر قياس، المتوسط، الأدنى، والأعلى؛ القائمة تُرتّب حسب متوسط الزمن (الأقل = أسرع في هذه الجلسة). الأسرع يحصل على شريط صغير — مع ذلك اقرأ التنبيه: الشبكة هي المهيمنة؛ هذا لقطة من جلستك وليس حكماً أدائياً مطلقاً.
baseURL، ترويسات، مهلة زمنية، وunwrapResponse لمثيل createClient.try/catch العشوائي.openFetch يستهدف الفرق التي تريد ذلك مع البقاء على fetch حيث يوفّره النظام.
createClient، أول طلباتrequest()rawResponse، دمج الإعداداتplugins وsugaruse()، وسيط مخصصOpenFetchError، الرموز، التسجيل الآمن، assertSafeHttpUrl| التصدير | الدور |
|---|---|
| الافتراضي | مثيل جاهز من createClient() |
createClient / create | عميل جديد مع initialDefaults اختيارية |
createFluentClient | سلاسل URL مرنة (من /sugar) |
retry, timeout, hooks, debug, strictFetch | إضافات وسيط (من /plugins) |
OpenFetchError، isOpenFetchError | أخطاء مُنمّاة + حارس النوع |
InterceptorManager | مكدس المعترضات |
createRetryMiddleware | مصنع وسيط إعادة المحاولة |
MemoryCacheStore، createCacheMiddleware، appendCacheKeyVaryHeaders | تخزين مؤقت في الذاكرة |
| الأنواع | OpenFetchConfig، OpenFetchResponse، Middleware، إلخ. |
assertSafeHttpUrl | حارس اختياري على نمط SSRF |
Node.js 18+ أو أي بيئة فيها fetch وAbortController.
تصفح كل الترجمات.