HTTP Status Code

رمز حالة HTTP

Beginnerbackend1 min read
status codehttp coderesponse code200 ok404 not found500 error401 unauthorized403 forbidden

Definition

Numeric codes returned by a server indicating whether an HTTP request succeeded or why it failed.

رموز رقمية تُعيدها الخادم تشير إلى ما إذا كان طلب HTTP قد نجح أو سبب فشله.

Why It Matters

On 404Fault, verifyAdminRequest() returning 401 vs 403 matters — 401 means unauthenticated, 403 means authenticated but not admin. Client-side code checks `if (!res.ok)` which catches any non-2xx code.

في 404Fault، إعادة verifyAdminRequest() للـ401 مقابل 403 مهمة — 401 تعني غير مصادق عليه، 403 تعني مصادق عليه لكن ليس مديرًا. الكود من جانب العميل يتحقق من `if (!res.ok)`.

Full Definition

HTTP responses include a status code: 2xx (success) — 200 OK, 201 Created, 204 No Content; 3xx (redirect) — 301 Moved, 302 Found; 4xx (client error) — 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 422 Unprocessable Entity; 5xx (server error) — 500 Internal Server Error. Next.js API routes return these via `NextResponse.json({}, { status: 401 })`.
استجابات HTTP تتضمن رمز حالة: 2xx (نجاح) — 200 OK، 201 Created؛ 4xx (خطأ العميل) — 400 Bad Request، 401 Unauthorized، 403 Forbidden، 404 Not Found؛ 5xx (خطأ الخادم) — 500 Internal Server Error.

Example Usage

return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); // vs return NextResponse.json({ error: 'Admin required' }, { status: 403 });

return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); // مقابل return NextResponse.json({ error: 'Admin required' }, { status: 403 });

Knowledge Graph

Avoid these mistakes when using HTTP Status Code:

1

Returning 200 with `{ error: '...' }` in the body — use the proper status code

2

Confusing 401 (not logged in) and 403 (logged in but not permitted)

Sign in to unlock guided AI explanations from AI Teacher.

Generate a Prompt

Copy this prompt and use it directly with any AI model — no setup needed.

Ready-to-Use Prompt
Help me build a project using HTTP Status Code.

Explain:
1. What is HTTP Status Code and why it matters
2. The core architecture and required tools
3. Step-by-step implementation plan
4. Common mistakes to avoid: Returning 200 with `{ error: '...' }` in the body — use the proper status code, Confusing 401 (not logged in) and 403 (logged in but not permitted)
5. Best practices and production tips

Official Resources