Status code HTTP

Semua status code HTTP terdaftar: artinya, kapan muncul, dan di mana didefinisikan.

100ContinueThe server received the request headers and the client should send the body.
101Switching ProtocolsThe server is switching to the protocol the client asked for in the Upgrade header.
102ProcessingThe server accepted the request and is still working on it.
103Early HintsHeaders sent ahead of the final response so the client can start preloading resources.
104Upload Resumption SupportedThe server supports resuming this upload if it is interrupted.
200OKThe request succeeded.
201CreatedThe request succeeded and created a new resource.
202AcceptedThe request was accepted for processing, which hasn't finished.
203Non-Authoritative InformationSuccess, but a proxy changed the response the origin server sent.
204No ContentThe request succeeded and there is no body.
205Reset ContentSuccess; the client should reset the form or view that sent the request.
206Partial ContentThe response holds only the byte range the client asked for.
207Multi-StatusThe body holds separate status codes for several operations.
208Already ReportedMembers of this collection were already listed earlier in the same 207 response.
226IM UsedThe response is a delta applied to the current instance, not the full resource.
300Multiple ChoicesThe resource has several representations and the client should choose one.
301Moved PermanentlyThe resource has a new permanent URL, given in the Location header.
302FoundThe resource is temporarily at the URL in the Location header.
303See OtherThe result is at another URL, which the client should fetch with GET.
304Not ModifiedThe cached copy is still valid, so no body is sent.
305Use ProxyThe resource must be accessed through the proxy in the Location header.
306(Unused)Reserved; it was once used for Switch Proxy and is no longer used.
307Temporary RedirectThe resource is temporarily at another URL; repeat the request there with the same method and body.
308Permanent RedirectThe resource has moved permanently; repeat the request at the new URL with the same method and body.
400Bad RequestThe server can't process the request because it is malformed.
401UnauthorizedThe request has no valid credentials for this resource.
402Payment RequiredReserved for future use.
403ForbiddenThe server understood the request but refuses to allow it.
404Not FoundThe server has nothing at this URL.
405Method Not AllowedThe resource exists but doesn't support this HTTP method.
406Not AcceptableThe server can't produce a response in any format the Accept headers allow.
407Proxy Authentication RequiredThe client must authenticate with the proxy first.
408Request TimeoutThe server gave up waiting for the client to finish sending the request.
409ConflictThe request conflicts with the current state of the resource.
410GoneThe resource existed but has been removed permanently.
411Length RequiredThe server needs a Content-Length header.
412Precondition FailedA condition in the request headers, such as If-Match, is false.
413Content Too LargeThe request body is larger than the server accepts.
414URI Too LongThe URL is longer than the server accepts.
415Unsupported Media TypeThe server doesn't accept the body's format.
416Range Not SatisfiableThe requested byte range is outside the resource.
417Expectation FailedThe server can't meet the Expect header.
418I'm a teapotA joke code from RFC 2324, kept reserved as "(Unused)" because so much software already recognizes it.
421Misdirected RequestThe request reached a server that can't answer for this host.
422Unprocessable ContentThe request is well formed but its content fails validation.
423LockedThe resource is locked.
424Failed DependencyThe request failed because a request it depended on failed.
425Too EarlyThe server won't process a request that might be replayed.
426Upgrade RequiredThe client must switch to another protocol, named in the Upgrade header.
428Precondition RequiredThe server requires a conditional request, such as one with If-Match.
429Too Many RequestsThe client has sent too many requests in a given time and is being rate limited.
431Request Header Fields Too LargeThe headers, or one header, are too large.
451Unavailable For Legal ReasonsThe resource can't be served for legal reasons.
500Internal Server ErrorThe server hit an unexpected condition.
501Not ImplementedThe server doesn't support the functionality needed, such as the request method.
502Bad GatewayA gateway or proxy got an invalid response from the server behind it.
503Service UnavailableThe server can't handle the request right now.
504Gateway TimeoutA gateway or proxy didn't get a response from the server behind it in time.
505HTTP Version Not SupportedThe server doesn't support the HTTP version of the request.
506Variant Also NegotiatesContent negotiation is misconfigured on the server.
507Insufficient StorageThe server can't store what it needs to complete the request.
508Loop DetectedThe server found an infinite loop while processing the request.
510Not ExtendedThe request needs an HTTP extension the server requires.
511Network Authentication RequiredThe client must authenticate to get network access.
419Page ExpiredLaravelThe CSRF token is missing or expired.
420Enhance Your CalmTwitter (historical)The client is being rate limited.
444No Responsenginxnginx closed the connection without sending a response.
494Request Header Too Largenginxnginx's code for headers over its buffer limits.
495SSL Certificate ErrornginxThe client certificate failed verification.
496SSL Certificate RequirednginxA required client certificate wasn't sent.
497HTTP Request Sent to HTTPS PortnginxA plain HTTP request reached a port that expects TLS.
499Client Closed RequestnginxThe client closed the connection before nginx sent the response.
509Bandwidth Limit ExceededApache / cPanelThe site has used up its bandwidth allowance.
520Web Server Returned an Unknown ErrorCloudflareThe origin server returned something Cloudflare couldn't use.
521Web Server Is DownCloudflareThe origin server refused Cloudflare's connection.
522Connection Timed OutCloudflareCloudflare couldn't establish a TCP connection to the origin in time.
523Origin Is UnreachableCloudflareCloudflare can't reach the origin server.
524A Timeout OccurredCloudflareCloudflare connected to the origin, but it didn't respond in time.
525SSL Handshake FailedCloudflareThe TLS handshake between Cloudflare and the origin failed.
526Invalid SSL CertificateCloudflareCloudflare couldn't validate the origin's certificate.
530Origin DNS ErrorCloudflareCloudflare returns 530 together with a 1xxx error, most often 1016 (origin DNS error).

Select a code

Pick a code from the list to see when it is used, the specification that defines it and a command to try it. Use the arrow keys to move through the list.
64 registered codes · 17 unofficial

Apa itu status code HTTP?

Setiap response HTTP diawali status code tiga digit yang menjelaskan apa yang terjadi pada request. Digit pertama menunjukkan kelasnya: 1xx berarti informasi, 2xx berarti sukses, 3xx berarti redirect, 4xx berarti request-nya salah, dan 5xx berarti server gagal.

Kode-kode ini didefinisikan di RFC 9110, HTTP Semantics, yang menggantikan RFC 7231 pada 2022, dan di beberapa RFC lain seperti RFC 6585 untuk 429 Too Many Requests. IANA mengelola registry resminya. RFC 9110 mengganti nama dua kode: 413 sekarang Content Too Large (sebelumnya Payload Too Large) dan 422 Unprocessable Content (sebelumnya Unprocessable Entity). Nomor dan perilakunya tidak berubah.

Beberapa kode yang Anda temui tidak ada di registry. nginx mencatat 499 saat klien menutup koneksi sebelum response siap, Cloudflare mengirim 520 sampai 526 saat tidak mendapat response yang bisa dipakai dari server origin, dan Laravel mengirim 419 saat token CSRF sebuah form sudah kedaluwarsa. Kode-kode ini didaftar terpisah dan ditandai tidak resmi.

Status code adalah hal pertama yang harus dicek dalam tes API, karena sisa response bergantung padanya. 201 Created memberi tahu bahwa POST membuat resource baru, 404 bahwa resource tidak ada, dan 500 bahwa server gagal, dan dalam hal ini body-nya bisa berupa halaman error, bukan JSON yang Anda harapkan.

Cara memakai tool ini

  1. 1Telusuri daftarnya, yang dikelompokkan dari 1xx sampai 5xx dengan kode tidak resmi di akhir, atau filter dengan tombol kelas.
  2. 2Cari berdasarkan nomor, nama, atau gejala, seperti 404, 5xx, redirect, timeout, atau nama lama seperti Unprocessable Entity. Tekan / untuk langsung ke kotak pencarian dari mana pun di halaman.
  3. 3Pilih sebuah kode, atau telusuri daftar dengan tombol panah, untuk melihat artinya, kapan muncul, spesifikasi yang mendefinisikannya, dan kode terkait untuk dibandingkan.
  4. 4Salin perintah curl di bawah Try it agar endpoint status testingapis.com mengembalikan kode itu, atau salin link: /id/tools/http-status/#429 langsung membuka 429.

Pemecahan masalah

Dapat 401 padahal sudah mengirim token
Token-nya kedaluwarsa, formatnya salah, dikirim di header yang salah, atau tidak ada prefix Bearer . Header response WWW-Authenticate sering menyebutkan yang mana. Sebaliknya, 403 berarti token valid tetapi tidak punya izin.
Dapat 415 untuk body JSON
Request tidak punya header Content-Type: application/json, jadi server tidak memperlakukan body sebagai JSON. -d di curl mengirim application/x-www-form-urlencoded kecuali Anda mengatur header-nya.
POST berubah menjadi GET setelah redirect
Klien mengikuti 301 dan 302 dengan mengulang request sebagai GET tanpa body. Server yang harus mempertahankan method sebaiknya mengirim 307 atau 308.
Dapat 502 atau 504 dari load balancer
Proxy di depan aplikasi tidak mendapat jawaban yang valid: 502 saat aplikasi crash atau menutup koneksi, 504 saat aplikasi butuh waktu lebih lama dari timeout proxy. Log aplikasi itu sendiri menunjukkan penyebabnya.
499 di log nginx
Klien menyerah sebelum response siap: pengguna meninggalkan halaman, atau klien atau proxy di hulu kena timeout. Penyebab yang paling umum adalah request backend yang lambat.

Pertanyaan umum

Apa beda 401 dan 403?

401 Unauthorized berarti server tidak tahu siapa Anda: kredensialnya tidak ada, kedaluwarsa, atau salah. 403 Forbidden berarti server tahu siapa Anda, tetapi identitas itu tidak diizinkan melakukan hal tersebut. Login ulang bisa memperbaiki 401, tetapi tidak 403.

Apakah API sebaiknya mengembalikan 400 atau 422 untuk input yang tidak valid?

Keduanya dipakai. Konvensi yang umum adalah 400 untuk request yang sama sekali tidak bisa dibaca server, seperti JSON yang rusak, dan 422 untuk data yang formatnya benar tetapi melanggar aturan, seperti field wajib yang hilang atau email yang tidak valid.

Apa beda 502, 503, dan 504?

Ketiganya biasanya berasal dari proxy atau load balancer di depan aplikasi. 502 Bad Gateway berarti proxy menerima response yang tidak valid dari server di belakangnya, 503 Service Unavailable berarti layanan sedang kelebihan beban atau dalam maintenance, dan 504 Gateway Timeout berarti server di belakangnya tidak menjawab tepat waktu.

Kode redirect mana yang sebaiknya saya pakai?

301 dan 308 bersifat permanen, 302 dan 307 sementara. 307 dan 308 mewajibkan klien mengulang request dengan method dan body yang sama, sedangkan klien biasanya mengubah POST menjadi GET setelah 301 atau 302. Gunakan 303 See Other untuk mengarahkan klien ke halaman hasil setelah POST.

Apakah 418 I'm a teapot status code sungguhan?

Kode ini berasal dari RFC 2324, lelucon April Mop tahun 1998 tentang mengendalikan teko kopi. RFC 9110 mencantumkan 418 sebagai tidak dipakai tetapi dicadangkan, karena sudah begitu banyak software yang mengenalinya. Kode ini tidak dimaksudkan untuk error sungguhan.

Bagaimana cara menguji cara aplikasi saya menangani status code tertentu?

Panggil endpoint yang mengembalikan kode yang Anda minta. GET https://api.testingapis.com/api/status/503 menjawab dengan 503 beserta header yang biasanya menyertai status itu, seperti Retry-After. Kode apa pun dari 200 sampai 599 bisa dipakai.