Rails Http Status Code For Validation Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the
Http Status Code For Invalid Credentials
workings and policies of this site About Us Learn more about Stack http status code for login failure Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions
Http Status Code For Failed Update
Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join rest http status codes best practices them; it only takes a minute: Sign up REST HTTP status codes for failed validation or invalid duplicate up vote 461 down vote favorite 128 I'm building an application with a REST-based API and have come to the point where i'm specifying status codes for each requests. What status code should i send for requests failing validation or where http status code resource already exists a request is trying to add a duplicate in my database? I've looked through http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html but none of them seems right. Is there a common practice when sending status codes? http rest http-status-codes share|improve this question edited Sep 3 '14 at 15:02 Raedwald 17.6k1265104 asked Jul 20 '10 at 13:03 alexn 33.8k879119 3 See: stackoverflow.com/questions/1959947/… –deamon Jul 20 '10 at 13:39 6 Open httpstatus.es, Right Click >> Pin Tab :P –Salman Abbas May 24 '12 at 5:00 add a comment| 7 Answers 7 active oldest votes up vote 414 down vote accepted For input validation failure: 400 Bad Request + your optional description. This is suggested in the book "RESTful Web Services". For double submit: 409 Conflict Update June 2014 The relevant specification used to be RFC2616, which gave the use of 400 (Bad Request) rather narrowly as The request could not be understood by the server due to malformed syntax So it might have been argued that it was inappropriate for semantic errors. But not any more; since June 2014 the rele
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us
Http Status Code 422
Learn more about Stack Overflow the company Business Learn more about hiring developers or rest status for whatsapp posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow
Apis Status Invalid Austrian Airlines
Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up What's an appropriate HTTP status code to return by http://stackoverflow.com/questions/3290182/rest-http-status-codes-for-failed-validation-or-invalid-duplicate a REST API service for a validation failure? up vote 190 down vote favorite 54 I'm currently returning 401 Unauthorized whenever I encounter a validation failure in my Django/Piston based REST API application. Having had a look at the HTTP Status Code Registry I'm not convinced that this is an appropriate code for a validation failure, what do y'all recommend? 400 Bad Request 401 Unauthorized 403 Forbidden http://stackoverflow.com/questions/1959947/whats-an-appropriate-http-status-code-to-return-by-a-rest-api-service-for-a-val 405 Method Not Allowed 406 Not Acceptable 412 Precondition Failed 417 Expectation Failed 422 Unprocessable Entity 424 Failed Dependency Update: "Validation failure" above means an application level data validation failure, i.e., incorrectly specified datetime, bogus email address etc. validation rest http-status-codes share|improve this question edited Dec 16 '13 at 2:58 George Stocker♦ 39.8k25132201 asked Dec 24 '09 at 22:34 michaeljoseph 2,64441720 1 Check out this answer: stackoverflow.com/a/2657624/221612 –Kenny Meyer Nov 26 '12 at 10:25 add a comment| 7 Answers 7 active oldest votes up vote 147 down vote accepted If "validation failure" means that there is some client error in the request, then use HTTP 400 (Bad Request). For instance if the URI is supposed to have an ISO-8601 date and you find that it's in the wrong format or refers to February 31st, then you would return an HTTP 400. Ditto if you expect well-formed XML in an entity body and it fails to parse. Note (1/2016): Over the last five years WebDAV's more specific HTTP 422 (Unprocessable Entity) has become a very reasonable alternative to HTTP 400. See for instance its use in JSON API Richardson and Ruby's RESTful Web Services contains a very helpful appendix on w
Forum → Rails & Code Javascript Disabled Detected You currently have javascript disabled. Several functions may not work. Please re-enable javascript to access full functionality. REST JSON API and validation errors Started by inish777 , Dec 06 2013 05:15 PM rails rest https://railsforum.com/topic/957-rest-json-api-and-validation-errors/ json Please log in to reply 2 replies to this topic #1 inish777 inish777 Passenger Members https://www.bennadel.com/blog/2434-http-status-codes-for-invalid-data-400-vs-422.htm 2 posts Posted 06 December 2013 - 05:15 PM Hi all! So, I want to made REST JSON API for my web app. It will be used by mobile apps, other web apps, etc. I have problem with ActiveRecord validation errors - it seems like they have no error codes, only messages. Of course, in case of error, I can return 422 HTTP status + http status error messages in JSON response body, but it seems to be better, if every error will have its own error code (50 for blank user name, 51 for blank password, etc) which will be returned in response body. Is it possible to implement in Rails or you can suggest other ways of error reporting? Back to top Report #2 james james Guard Members 223 posts LocationLeeds, U.K. Posted 07 December 2013 - 10:54 AM Best Answer api's should stick http status code to standard http protocols so stick with the 4xx and 5xx error codes. Why not include a status code with the error message? That can then be interpreted by the user of the api? Custom error messages are not difficult to implement just add them to the erros object of the model instance. You can add multiple errors. You can just push them errors[:base] << "50" There is even no reason why the error couldn't be a hash instead of just a string errors[:base] << "{code: 50}" untested so you might need to play with that a bit. http://api.rubyonrai...del/Errors.html inish777 likes this Programming is just about problem solving! Back to top Report #3 inish777 inish777 Passenger Members 2 posts Posted 07 December 2013 - 01:00 PM Thanks! Back to top Report Back to Rails & Code Also tagged with one or more of these keywords: rails, rest, json Rails Forum → Rails & Code → Capistrano - commit capistrano config before deploy? Started by swigrid , 11 Aug 2016 capistrano, rails, deploy, commit and 1 more... 0 replies 243 views swigrid 11 Aug 2016 Rails Forum → Rails & Code → Learning Rails and needs a partner or mentor! Started by Tyrese W. , 24 Jul 2016 rails, mentor, team, project and 1 more... 0 replies 286 views Tyrese W. 24 Jul 2016 Rails Forum → Rails & Code →
Codes For Invalid Data: 400 vs. 422 By Ben Nadel on October 17, 2012 Tags: ColdFusion Let's say that someone makes a request to your server with data that is in the correct format, but is simply not "good" data. So for example, imagine that someone posted a String value to an API endpoint that expected a String value; but, the value of the string contained data that was blacklisted (ex. preventing people from using "password" as their password). What HTTP status code would you return?Until now, I would have returned a "400 Bad Request", which, according to the w3.org, means:The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.This description doesn't quite fit the circumstance; but, if you go by the list of core HTTP status codes defined in the HTTP/1.1 protocol, it's probably your best bet.Recently, however, Jamie Krug pointed out [to me] that popular APIs are starting to use HTTP extensions to get more granular with their error reporting. Specifically, many APIs, like Twitter and Recurly, are using the status code "422 Unprocessable Entity" as defined in the HTTP extension for WebDAV. HTTP status code 422 states:The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415 (Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions. For example, this error condition may occur if an XML request body contains well-formed (i.e., syntactically correct), but semantically erroneous, XML instructions.Going back to our password example from above, this 422 status code feels much more appropriate. The server understands what you're trying to do; and it understands the data that you're submitting; it simply won't let that data be processed.HTTP status code 422 feels like a much more appropriate response for situations where the data is understood, but is still not valid. I think I'll start using this going forward. Thanks Jamie! Tweet This Provocative thoughts by @BenNadel - HTTP Status Codes For Invalid Data: 400 vs. 422 Thanks my man — you rock the party that rocks the body! Enjoyed This? You Might Also Enjoy Reading: Handling Forbidden RESTful Requests: 401 vs. 403 vs. 404 Building A Twitter-Inspired RESTful API Architecture In ColdFusion Using Appropriate Status Codes With Each API Response Looking For A New Job? View All Jobs