Ruby on Rails HTTP Status codes

Ruby on Rails HTTP Status codes

Tagged under:  #ruby-on-rails#development

When working on a rails application (or specially on an api) it’s not uncommon to have to handle different http status codes.

At some point, we end up getting to know some of them, but the truth is that there are a lot, and the good news is that if you’re writing a ruby on rails application, there are mappings to handle the status codes by their name.

You can quickly take a look at the list of status codes by simply loading a rails console bundle exec rails console and then check Rack::Utils::HTTP_STATUS_CODES or Rack::Utils::SYMBOL_TO_STATUS_CODE to get the whole list of supported status codes on rails.

The table below contains all the supported status codes on rails with their full names and the corresponding ruby symbols.

101Switching Protocols:switching_protocols
103Early Hints:early_hints
203Non-Authoritative Information:non_authoritative_information
204No Content:no_content
205Reset Content:reset_content
206Partial Content:partial_content
208Already Reported:already_reported
226IM Used:im_used
300Multiple Choices:multiple_choices
301Moved Permanently:moved_permanently
303See Other:see_other
304Not Modified:not_modified
305Use Proxy:use_proxy
307Temporary Redirect:temporary_redirect
308Permanent Redirect:permanent_redirect
400Bad Request:bad_request
402Payment Required:payment_required
404Not Found:not_found
405Method Not Allowed:method_not_allowed
406Not Acceptable:not_acceptable
407Proxy Authentication Required:proxy_authentication_required
408Request Timeout:request_timeout
411Length Required:length_required
412Precondition Failed:precondition_failed
413Payload Too Large:payload_too_large
414Request-URI Too Long:uri_too_long
415Unsupported Media Type:unsupported_media_type
416Requested Range Not Satisfiable:range_not_satisfiable
417Expectation Failed:expectation_failed
421Misdirected Request:misdirected_request
422Unprocessable Entity:unprocessable_entity
424Failed Dependency:failed_dependency
425Too Early:too_early
426Upgrade Required:upgrade_required
428Precondition Required:precondition_required
429Too Many Requests:too_many_requests
431Request Header Fields Too Large:request_header_fields_too_large
451Unavailable for Legal Reasons:unavailable_for_legal_reasons
500Internal Server Error:internal_server_error
501Not Implemented:not_implemented
502Bad Gateway:bad_gateway
503Service Unavailable:service_unavailable
504Gateway Timeout:gateway_timeout
505HTTP Version Not Supported:http_version_not_supported
506Variant Also Negotiates:variant_also_negotiates
507Insufficient Storage:insufficient_storage
508Loop Detected:loop_detected
509Bandwidth Limit Exceeded:bandwidth_limit_exceeded
510Not Extended:not_extended
511Network Authentication Required:network_authentication_required

That’s a lot of codes 😅 I’ll try to keep that table updated as new codes get added.