أهداف الدرس
- أن تسمّي العناوين بالأسماء لا بالأفعال.
- أن تعيد رمز الحالة الصحيح.
الواجهة الجيدة تُقرأ كجملة: /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
- Name addresses with nouns, not verbs.
- 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.
| Code | When |
|---|---|
| 200 OK | We found it |
| 201 Created | We created something |
| 400 Bad Request | The request itself is wrong |
| 401 / 403 | Not signed in / not allowed |
| 404 Not Found | Not there |
POST /api/pages
Content-Type: application/json
{ "title": "Lesson 1", "language": "ar" }
HTTP/1.1 201 Created
Location: /api/pages/12Exercise
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.