Skip to main content

std.net — HTTP Status Codes

Use named constants instead of magic numbers for both client checks and server responses.

std.net.http_codes.ok // 200
std.net.http_codes.not_found // 404
std.net.http_codes.internal_server_error // 500

// client:
var r = std.net.http_client().request({url: "http://127.0.0.1:8200/"})
if (r.status == std.net.http_codes.ok) { print(r.body) }

// server:
return {status: std.net.http_codes.not_found, body: "nope"}

Table

ConstantCode
ok200
created201
accepted202
no_content204
moved_permanently301
found302
not_modified304
bad_request400
unauthorized401
forbidden403
not_found404
method_not_allowed405
conflict409
gone410
payload_too_large413
unsupported_media_type415
too_many_requests429
im_a_teapot418
internal_server_error500
not_implemented501
bad_gateway502
service_unavailable503
gateway_timeout504

All constants live under std.net.http_codes. Use them in both HTTP Client status checks and HTTP Server response objects.

See also