HTTP स्टेटस कोड संदर्भ

स्पष्टीकरण और उपयोग के मामलों के साथ HTTP प्रतिक्रिया स्थिति कोड का पूर्ण संदर्भ।

HTTP स्टेटस कोड श्रेणियाँ

301 और 302 में क्या अंतर है?

301 Moved Permanently क्लाइंट को बताता है कि संसाधन स्थायी रूप से स्थानांतरित हो गया · खोज इंजन नए URL को इंडेक्स करते हैं। 302 Found अस्थायी है।

401 बनाम 403 कब उपयोग करें?

401 Unauthorized का अर्थ "अनप्रमाणित" · क्लाइंट को प्रमाणपत्र प्रदान करने चाहिए। 403 Forbidden का अर्थ है कि क्लाइंट प्रमाणित है परंतु उसकी पहुँच नहीं है।

स्टेटस कोड 418 का क्या अर्थ है?

418 "I'm a teapot" RFC 2324 (Hyper Text Coffee Pot Control Protocol) का एक अप्रैल फूल मज़ाक है।

तीन Decades के Drift के साथ एक Standard

HTTP status codes कई spec generations से live हैं। RFC 1945 (May 1996) ने HTTP/1.0 को basic 1xx-5xx categories के साथ standardise किया। RFC 2616 (June 1999) ने HTTP/1.1 ship किया और एक decade से अधिक के लिए canonical reference था। 7230-7235 series (June 2014) ने HTTP/1.1 को topic के हिसाब से multiple specs में split किया। Current consolidated standard RFC 9110 «HTTP Semantics» (June 2022) है, जो 7230-7235 split को obsolete करता है और modern work के लिए सही citation है। Assigned codes का full live registry IANA's HTTP status code registry पर live है।

एक नज़र में पांच Categories

«vs» Comparisons जो सबको Trip करती हैं

401 vs 403. सबसे confusing pair। 401 Unauthorized का मतलब है «आपने authenticate नहीं किया है, login करने की कोशिश करें» (नाम technically misleading है, यह authentication के बारे में है, authorization के बारे में नहीं)। 403 Forbidden का मतलब है «आप authenticated हैं, लेकिन आपको यह करने की permission नहीं है», आपके credentials valid हैं लेकिन वे इस resource तक access grant नहीं करते। एक common misuse: unauthenticated requests के लिए 403 return करना जब 401 के साथ WWW-Authenticate header correct है।

301 vs 302 vs 307 vs 308. दो axes, permanent vs temporary, और method-preservation behaviour:

कोडPermanent?Method बरकरार?SEO ranking संकेत
301 Moved Permanentlyहांऐतिहासिक रूप से clients ने POST को → GET में change कियाPermanent, ranking नए URL को pass होती है
302 Foundनहींऐतिहासिक रूप से clients ने POST को → GET में change कियाTemporary, original URL ranking रखती है
307 Temporary RedirectनहींStrict, POST का POST रहता है302 जैसा
308 Permanent RedirectहांStrict, POST का POST रहता है301 जैसा

यदि आप SEO purposes के लिए GET requests redirect कर रहे हैं, तो 301 conventional choice है। यदि आप POST या PUT requests redirect कर रहे हैं और method preserved चाहते हैं, तो 307 या 308 चाहिए।

400 vs 422. 400 Bad Request syntactically malformed requests के लिए है, invalid JSON, missing required headers, malformed query parameters। 422 Unprocessable Entity (originally एक WebDAV code, REST APIs द्वारा widely adopted) syntactically valid requests के लिए है जिनमें semantic problems हों, JSON correctly parse होता है, लेकिन values business validation fail करती हैं (order पर negative quantity, email already in use)। कई APIs दोनों use करते हैं।

502 vs 503 vs 504. तीन different upstream-failure modes:

404 vs 410. 404 Not Found है «हम नहीं जानते यह exist करता है या नहीं।» 410 Gone है «यह exist करता था, यह permanently removed है।» SEO impact: Google 410 को एक stronger signal treat करता है कि content permanently unavailable है और इसे 404 की तुलना में index से faster remove करता है।

REST API परंपराएं

Modern REST APIs ने काफी consistent set of conventions converge किए हैं कि किन actions के लिए कौन से status codes का क्या मतलब है:

Methodसामान्य स्थितिसामान्य errors
GETbody के साथ 200 OK, या cached होने पर 304 Not Modifiedresource missing होने पर 404, forbidden होने पर 403
POST (बनाना)201 Created, नए resource की ओर Location header के साथmalformed body के लिए 400, validation errors के लिए 422, conflicts के लिए 409
PUT (प्रतिस्थापित) / PATCH (अपडेट)updated body के साथ 200 OK, या 204 No Contentresource missing होने पर 404, version conflicts के लिए 409
DELETE204 No Content (या deletion confirmation के साथ 200)missing होने पर 404
कोई भी (rate-limited)-429 Too Many Requests, Retry-After header के साथ
कोई भी (auth)-auth नहीं होने पर 401, authorised है लेकिन permitted नहीं होने पर 403

SEO प्रभाव

Famous & Cultural Codes

सामान्य गलतियाँ

  1. Errors के लिए 200 OK use करना error body के साथ। {"error": "not found"} को 200 status के साथ return करना हर caching layer, monitoring tool, और client SDK को confuse करता है। सही status code use करें।
  2. Unauthenticated requests के लिए 403 return करना। सही code 401 है WWW-Authenticate header के साथ।
  3. 302 use करना जब 301 का मतलब हो। यदि move permanent है, तो search engines को ranking transfer करने के लिए 301 चाहिए। 302 old URL को indexed रखता है।
  4. POST/PUT redirects के लिए 301 या 302 use करना। ऐतिहासिक रूप से इन्होंने clients को method को GET में change करने की permission दी। 307 और 308 strictly original method preserve करते हैं।
  5. 500 return करना जब 503 का मतलब हो। यदि server overloaded है या maintenance में है, तो 503 Retry-After के साथ सही signal है, clients और Googlebot दोनों के लिए।
  6. Permanently-removed pages के लिए 404 use करना। 410 Gone stronger signal है और search-engine indexes से faster remove होता है।
  7. Location header भूलना 201 और 3xx responses पर। Location header ही client को बताता है कि नया resource कहां live करता है या redirect कहां करना है। इसके बिना, clients navigate नहीं कर सकते।

अधिक अक्सर पूछे जाने वाले प्रश्न

मुझे 422 कब return करना चाहिए 400 की जगह?

400 Bad Request का मतलब है request itself malformed है, invalid JSON, missing required headers, malformed query parameters। 422 Unprocessable Entity का मतलब है request well-formed है लेकिन इसमें semantic errors हैं जो processing prevent करती हैं, एक quantity field जो negative number पर set है, एक email address जो already in use है, एक future-only field के लिए past date। Modern REST API conventions इस split पर converge हो गए हैं, अधिकांश large APIs (GitHub, Stripe, Twilio) validation errors के लिए 422 use करते हैं।

Cloudflare sometimes 520, 521, 522… क्यों return करता है?

520-527 codes Cloudflare-specific हैं, different ways signal करते हैं जिनसे उनका edge आपके origin server तक नहीं पहुंच सका। 520 generic «web server returned an unknown error» है; 521 का मतलब आपके origin ने connection refuse किया; 522 आपके origin में connection timeout है; 524 का मतलब आपके origin ने respond करने में बहुत लंबा समय लिया। ये IANA registry में नहीं हैं लेकिन widely encountered हैं जब Cloudflare के पीछे sites में backend issues होती हैं।

क्या मेरा browser मुझे बताएगा कि मेरे API ने कौन सा code return किया?

हां, DevTools → Network tab open करें, request पर click करें, और «Status» column देखें। Browsers कुछ codes के लिए generic pages भी display करते हैं (Chrome के connection failures पर dinosaur game, standard 404 / 500 pages); लेकिन actual numeric code हमेशा response में होता है।

103 Early Hints क्या है?

A relatively new (RFC 8297, 2017) 1xx code जो server को full response ready होने से पहले Link: rel=preload headers send करने देता है, browser को critical resources (CSS, fonts, images) पहले से fetch करना शुरू करने के लिए बताता है। अब Chrome द्वारा supported और Cloudflare, Fastly, और अन्य CDNs द्वारा performance optimisation के रूप में shipped।

क्या मैं अपना खुद का status code बना सकता हूं?

Technically हां (HTTP 100-599 range में किसी भी 3-digit code को allow करता है। Practically नहीं) clients, proxies, और caches unknown codes को उनके first digit से treat करते हैं (तो 4xx = generic client error, 5xx = server error)। कुछ vendors ऐसा करते हैं (Cloudflare के 520s, Nginx के 444), लेकिन जब तक आप wire के दोनों ends control नहीं करते, IANA registry से stick रहें। एक 299 invent करना चीज़ें break नहीं करेगा लेकिन कुछ communicate भी नहीं करेगा।

«status code» को «status» क्यों कहा जाता है और «error code» नहीं?

क्योंकि उनमें से ज़्यादातर errors नहीं हैं। 200 OK दुनिया में सबसे ज़्यादा returned status code है, इसका मतलब है «everything went fine.» Codes request के status communicate करते हैं: success, redirect, client error, server error। उन्हें «error codes» कहना negative cases की ओर bias करता है जो logged और noticed होते हैं; success codes हर microsecond चुपचाप अपना काम कर रहे होते हैं।

संबंधित टूल

URL पार्सर .htaccess फ़ाइल जनरेटर मुफ़्त URL एन्कोडर / डिकोडर