Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
2xx Success
200 :ok
201 :created
202 :accepted
203 :non_authoritative_information
204 :no_content
205 :reset_content
206 :partial_content
207 :multi_status
226 :im_used
3xx Redirection
300 :multiple_choices
301 :moved_permanently
302 :found
303 :see_other
304 :not_modified
305 :use_proxy
307 :temporary_redirect
4xx Client Error
400 :bad_request
401 :unauthorized
402 :payment_required
403 :forbidden
404 :not_found
405 :method_not_allowed
406 :not_acceptable
407 :proxy_authentication_required
408 :request_timeout
409 :conflict
410 :gone
411 :length_required
412 :precondition_failed
413 :request_entity_too_large
414 :request_uri_too_long
415 :unsupported_media_type
416 :requested_range_not_satisfiable
417 :expectation_failed
422 :unprocessable_entity
423 :locked
424 :failed_dependency
426 :upgrade_required
5xx Server Error
500 :internal_server_error
501 :not_implemented
502 :bad_gateway
503 :service_unavailable
504 :gateway_timeout
505 :http_version_not_supported
507 :insufficient_storage
510 :not_extended
@juanpastas

This comment has been minimized.

Copy link

commented Aug 4, 2016

Is not there a map inside Rails?

@juanpastas

This comment has been minimized.

Copy link

commented Aug 4, 2016

Found Rack::Utils::HTTP_STATUS_CODES.

@AlexVPopov

This comment has been minimized.

Copy link

commented Aug 5, 2016

@juanpastas In Rack::Utils you also have SYMBOL_TO_STATUS_CODE,which matches the symbol names to the numeric values.

@cesc1989

This comment has been minimized.

Copy link

commented Sep 15, 2016

Cool. Never used them because didn't take the time to find the list. Gonna fork this. Thanks a lot.

@richpeck

This comment has been minimized.

Copy link

commented Aug 24, 2017

@artur-beljajev

This comment has been minimized.

Copy link

commented Aug 3, 2019

No 3rd party code needed:

require 'net/http'

p Net::HTTPResponse::CODE_TO_OBJ

=> {"100"=>Net::HTTPContinue, "101"=>Net::HTTPSwitchProtocol, "200"=>Net::HTTPOK, "201"=>Net::HTTPCreated, "202"=>Net::HTTPAccepted, "203"=>Net::HTTPNonAuthoritativeInformation, "204"=>Net::HTTPNoContent, "205"=>Net::HTTPResetContent, "206"=>Net::HTTPPartialContent, "207"=>Net::HTTPMultiStatus, "226"=>Net::HTTPIMUsed, "300"=>Net::HTTPMultipleChoices, "301"=>Net::HTTPMovedPermanently, "302"=>Net::HTTPFound, "303"=>Net::HTTPSeeOther, "304"=>Net::HTTPNotModified, "305"=>Net::HTTPUseProxy, "307"=>Net::HTTPTemporaryRedirect, "308"=>Net::HTTPPermanentRedirect, "400"=>Net::HTTPBadRequest, "401"=>Net::HTTPUnauthorized, "402"=>Net::HTTPPaymentRequired, "403"=>Net::HTTPForbidden, "404"=>Net::HTTPNotFound, "405"=>Net::HTTPMethodNotAllowed, "406"=>Net::HTTPNotAcceptable, "407"=>Net::HTTPProxyAuthenticationRequired, "408"=>Net::HTTPRequestTimeOut, "409"=>Net::HTTPConflict, "410"=>Net::HTTPGone, "411"=>Net::HTTPLengthRequired, "412"=>Net::HTTPPreconditionFailed, "413"=>Net::HTTPRequestEntityTooLarge, "414"=>Net::HTTPRequestURITooLong, "415"=>Net::HTTPUnsupportedMediaType, "416"=>Net::HTTPRequestedRangeNotSatisfiable, "417"=>Net::HTTPExpectationFailed, "422"=>Net::HTTPUnprocessableEntity, "423"=>Net::HTTPLocked, "424"=>Net::HTTPFailedDependency, "426"=>Net::HTTPUpgradeRequired, "428"=>Net::HTTPPreconditionRequired, "429"=>Net::HTTPTooManyRequests, "431"=>Net::HTTPRequestHeaderFieldsTooLarge, "500"=>Net::HTTPInternalServerError, "501"=>Net::HTTPNotImplemented, "502"=>Net::HTTPBadGateway, "503"=>Net::HTTPServiceUnavailable, "504"=>Net::HTTPGatewayTimeOut, "505"=>Net::HTTPVersionNotSupported, "507"=>Net::HTTPInsufficientStorage, "511"=>Net::HTTPNetworkAuthenticationRequired}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.