std.net.http_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

Constant Code
ok 200
created 201
accepted 202
no_content 204
moved_permanently 301
found 302
not_modified 304
bad_request 400
unauthorized 401
forbidden 403
not_found 404
method_not_allowed 405
conflict 409
gone 410
payload_too_large 413
unsupported_media_type 415
too_many_requests 429
im_a_teapot 418
internal_server_error 500
not_implemented 501
bad_gateway 502
service_unavailable 503
gateway_timeout 504

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

See also