http-status-codes
HTTP Status 424 or 500 for error on external dependency
The failure you’re asking about is one that has occurred within the internals of the service itself, so a 5xx status code range is the correct choice. 503 Service Unavailable looks perfect for the situation you’ve described. 5xx codes are for telling the client that even though the request was fine, the server has had … Read more
Is it wrong to return 202 “Accepted” in response to HTTP GET?
If it’s for a well-defined and -documented API, 202 sounds exactly right for what’s happening. If it’s for the public Internet, I would be too worried about client compatibility. I’ve seen so many if (status == 200) hard-coded…. In that case, I would return a 200. Also, the RFC makes no indication that using 202 … Read more
Set Response Status Code [duplicate]
PHP <=5.3 The header() function has a parameter for status code. If you specify it, the server will take care of it from there. header(‘HTTP/1.1 401 Unauthorized’, true, 401); PHP >=5.4 See Gajus’ answer: https://stackoverflow.com/a/14223222/362536
Script to get the HTTP status code of a list of urls?
Curl has a specific option, –write-out, for this: $ curl -o /dev/null –silent –head –write-out ‘%{http_code}\n’ <url> 200 -o /dev/null throws away the usual output –silent throws away the progress meter –head makes a HEAD HTTP request, instead of GET –write-out ‘%{http_code}\n’ prints the required status code To wrap this up in a complete Bash … Read more
Convention for HTTP response header to notify clients of deprecated API
I would not change anything in the status code to be backward compatible. I would add a “Warning” header in the response : Warning: 299 – “Deprecated API” You can also specify the “-” with the “Agent” that emits the warning, and be more explicit in the warn-text : Warning: 299 api.blazingFrog.com “Deprecated API: use … Read more
Laravel – Return json along with http status code
You can use http_response_code() to set HTTP response code. If you pass no parameters then http_response_code will get the current status code. If you pass a parameter it will set the response code. http_response_code(201); // Set response status code to 201 For Laravel(Reference from: https://stackoverflow.com/a/14717895/2025923): return Response::json([ ‘hello’ => $value ], 201); // Status code … Read more
How do I resolve a HTTP 414 “Request URI too long” error?
Under Apache, the limit is a configurable value, LimitRequestLine. Change this value to something larger than its default of 8190 if you want to support a longer request URI. The value is in /etc/apache2/apache2.conf. If not, add a new line (LimitRequestLine 10000) under AccessFileName .htaccess. However, note that if you’re actually running into this limit, … Read more
What is the appropriate HTTP status code response for a general unsuccessful request (not an error)?
You should use 400 for business rules. Don’t return 2xx if the order was not accepted. HTTP is an application protocol, never forget that. If you return 2xx the client can assume the order was accepted, regardless of any information you send in the body. From RESTful Web Services Cookbook: One common mistake that some … Read more
HTTP status code for a partial successful request
I’ve dealt with a very similar issue. In this case, I returned a 207 Multi-Status Now, this isn’t strict HTTP, it’s part of the WebDAV extension, so if you don’t have control over the client too, then this isn’t good for you. If you do, you could do something like so: <?xml version=”1.0″ encoding=”utf-8″ ?> … Read more