واجهة برمجية واضحة / A clear API

الترتيب / Order
2 من 4 / 2 of 4
آخر تحديث / Updated
8 أكتوبر 2026 / 8 October 2026

أهداف الدرس

  1. أن تسمّي العناوين بالأسماء لا بالأفعال.
  2. أن تعيد رمز الحالة الصحيح.

الواجهة الجيدة تُقرأ كجملة: /pages/12 هي الصفحة رقم 12، والطريقة تقول ماذا نفعل بها.

الرمزمتى
200 OKوجدنا ما طلبت
201 Createdأنشأنا شيئاً جديداً
400 Bad Requestالطلب نفسه خطأ
401 / 403لم تدخل / لا يُسمح لك
404 Not Foundغير موجود
POST /api/pages
Content-Type: application/json

{ "title": "Lesson 1", "language": "ar" }

HTTP/1.1 201 Created
Location: /api/pages/12

تمرين

ما الرمز إن طلب زائر صفحة حُذفت؟

الإجابة

404، لأن الصفحة غير موجودة الآن.

Lesson goals

  1. Name addresses with nouns, not verbs.
  2. Return the right status code.

A good API reads like a sentence: /pages/12 is page 12, and the method says what to do with it.

CodeWhen
200 OKWe found it
201 CreatedWe created something
400 Bad RequestThe request itself is wrong
401 / 403Not signed in / not allowed
404 Not FoundNot there
POST /api/pages
Content-Type: application/json

{ "title": "Lesson 1", "language": "ar" }

HTTP/1.1 201 Created
Location: /api/pages/12

Exercise

Which code if a visitor asks for a deleted page?

Answer

404, because the page is not there now.

التعليقات / Comments

لا تعليقات بعد. كن أول من يسأل. / No comments yet. Be the first to ask.

تعليق الطالب يظهر فوراً، وتعليق الزائر بعد موافقة المدرّس. / A student's comment shows at once; a visitor's once the teacher approves it.

في «الخوادم والواجهات البرمجية» / In “Servers and APIs”

  1. 1الطلب والرد / Request and responseفيها كود / has codeالتعليقات مفتوحة / comments open
  2. 2واجهة برمجية واضحة / A clear APIفيها كود / has codeالتعليقات مفتوحة / comments open
  3. 3رحلة الطلب / A request's journeyفيها صور / has picturesالتعليقات مفتوحة / comments open
  4. 4الدخول والصلاحيات / Sign-in and permissionsالتعليقات مفتوحة / comments open

↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق↑ ↓ to move · Enter to open · Esc to close