An enum that provides additional support around HTTP status codes.
Based on Hypertext Transfer Protocol (HTTP) Status Code Registry
It provides constants for the defined HTTP status codes as well as helper methods to easily identify the type of response.
100
101
102
103
200
201
202
203
204
205
206
207
208
226
300
301
302
303
304
305
306
307
308
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
421
422
423
424
426
428
429
431
451
500
501
502
503
504
505
506
507
508
510
511
Create a new status instance with the given status code, or raise an error if the status code given is not inside 100..999.
Returns true
if the response status code is between 400 and 499.
Returns the number that represents the HTTP status code.
Returns the default status description of the given HTTP status code.
Returns true
if the response status code is between 100 and 199.
Returns true
if the response status code is between 300 and 399.
Returns true
if the response status code is between 500 and 599.
Returns true
if the response status code is between 200 and 299.
Enum
Enum
Enum
Comparable(Enum)
Value
Object
Object
Create a new status instance with the given status code, or raise an error if the status code given is not inside 100..999.
require "http/status" HTTP::Status.new(100) # => CONTINUE HTTP::Status.new(202) # => ACCEPTED HTTP::Status.new(123) # => 123 HTTP::Status.new(1000) # raises ArgumentError
Returns true
if the response status code is between 400 and 499.
require "http/status" HTTP::Status::METHOD_NOT_ALLOWED.client_error? # => true HTTP::Status::INTERNAL_SERVER_ERROR.client_error? # => false
Returns the number that represents the HTTP status code.
require "http/status" status = HTTP::Status::NO_CONTENT status.code # => 204
Returns the default status description of the given HTTP status code.
require "http/status" HTTP::Status.new(123).description # => nil HTTP::Status::NO_CONTENT.description # => "No Content" HTTP::Status::METHOD_NOT_ALLOWED.description # => "Method Not Allowed" HTTP::Status::INTERNAL_SERVER_ERROR.description # => "Internal Server Error"
Returns true
if the response status code is between 100 and 199.
require "http/status" HTTP::Status::SWITCHING_PROTOCOLS.informational? # => true HTTP::Status::INTERNAL_SERVER_ERROR.informational? # => false
Returns true
if the response status code is between 300 and 399.
require "http/status" HTTP::Status::SWITCH_PROXY.redirection? # => true HTTP::Status::INTERNAL_SERVER_ERROR.redirection? # => false
Returns true
if the response status code is between 500 and 599.
require "http/status" HTTP::Status::INTERNAL_SERVER_ERROR.server_error? # => true HTTP::Status::METHOD_NOT_ALLOWED.server_error? # => true
Returns true
if the response status code is between 200 and 299.
require "http/status" HTTP::Status::NO_CONTENT.success? # => true HTTP::Status::INTERNAL_SERVER_ERROR.success? # => false
© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/HTTP/Status.html