http-status-codes

What's the most appropriate HTTP status code for an “item not found” error page

孤街浪徒 提交于 2019-11-28 18:04:31
I'm curious what's the most appropriate HTTP status code for an "item does not exist" page. If the page itself doesn't exist, I'll obviously use 404. However, one of my pages has a userid argument (it's an "edit user" page) and in case no user with the given user ID exists I'm displaying an error page, but I'd also like to send a 4xx status header (since "200 OK" doesn't really fit). I guess 404 would be ok since it's "not found" and not "file not found", but I wonder if there's a better code for this case. Getting overly clever with obscure-er HTTP error codes is a bad idea. Browsers

Laravel - Return json along with http status code

对着背影说爱祢 提交于 2019-11-28 17:43:18
If I return an object: return Response::json([ 'hello' => $value ]); the status code will be 200. How can I change it to 201, with a message and send it with the json object?. I don't know if there is a way to just set the status code in Laravel. Tushar 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

Convention for HTTP response header to notify clients of deprecated API

若如初见. 提交于 2019-11-28 17:29:09
问题 I'm upgrading our REST API endpoints and I want to notify clients when they are calling the to-be-deprecated endpoint. What header should I use in the response with a message along the lines of "This API version is being deprecated, please consult the latest documentation to update your endpoints" 回答1: 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

How do I choose a HTTP status code in REST API for “Not Ready Yet, Try Again Later”? [closed]

我的梦境 提交于 2019-11-28 16:08:00
I'm developing a RESTful API in which http://server/thingyapi/thingyblob/1234 returns the file (aka "blob") associated with thingy #1234 to download. But it may be that the request is made at a time the file does not exist in the server but most definitely will be available at a later time. There's a batch process in the server that generates all the blobs for all the thingies. Thingy 1234 already exists and its data, other than the blob, is already available. The server hasn't got to generating thingy 1234's blob yet. I don't want to return 404; that's for thingies that do not exist. This is

Angular HTTP: Status -1 and CORS

半世苍凉 提交于 2019-11-28 13:47:45
In our angular application sometimes we get http status -1 returned to us. The status -1 happens on a popup that is closed, so the user isn't affected by it, just our logs. I attempted to handle it by doing switch (response.status) { case 0: break; case -1: break; case 401: localStorageService.clearAll(); redirectToUrlAfterLogin.url = $location.path(); $location.path('/login'); Which was suggested in AngularJS Issue #12920 We are definitely getting less logs in, but there are still some HTTP -1 status codes. Is there a different way I should be handling the -1? Muthukannan Kanniappan When the

Python CGI returning an http status code, such as 403?

僤鯓⒐⒋嵵緔 提交于 2019-11-28 11:58:09
How can my python cgi return a specific http status code, such as 403 or 418? I tried the obvious (print "Status:403 Forbidden") but it doesn't work. print 'Status: 403 Forbidden' print Works for me. You do need the second print though, as you need a double-newline to end the HTTP response headers. Otherwise your web server may complain you aren't sending it a complete set of headers. sys.stdout('Status: 403 Forbidden\r\n\r\n') may be technically more correct, according to RFC (assuming that your CGI script isn't running in text mode on Windows). However both line endings seem to work

HTTP status code for unaccepted Content-Type in request

不羁的心 提交于 2019-11-28 10:39:38
For certain resources, my RESTful server only accepts PUT and POST requests with JSON objects as the content body, thus requiring a Content-Type of application/json instead of application/x-www-form-urlencoded or multipart/form-data or anything else. Malformed JSON (or lack thereof) returns a 400 with the error message taken directly from the exception raised by the JSON parser, for debugging purposes. Which HTTP error code means that the client sent a request with an unacceptable Content-Type , even if the server could technically parse the request content? William Durand It could be 415

HTTP status code for temporarily unavailable pages

ⅰ亾dé卋堺 提交于 2019-11-28 07:54:19
I'm redesigning my small business' website. I will be putting up a temporarily 'under construction' splash page. I know, I know... but it will be one in style, I hope. :) What, mostly for SEO purposes, is the best HTTP status code to dish out for the URLs that will be temporarily unavailable (the same URLs will have content again, after the new site is up). Now, my website traffic is hardly of any importance, but as a webdeveloper I want this knowledge in my toolbox for possible future client projects. And what better way to test and experiment with this, now that I have a convenient 'reason'

Why does $.ajax call for json data trigger the error callback when http status code is “200 OK”?

試著忘記壹切 提交于 2019-11-28 07:36:30
问题 I have the following ajax request: jQuery.ajax({ async: true, type: "GET", url: url, data: data, dataType: "json", success: function(results){ currentData = results; }, error: function(xhr, ajaxOptions, thrownError){ if (xhr.status == 200) { console.debug("Error code 200"); } else { currentData = {}; displayAjaxError(xhr.status); } } }); For some reason the error callback is called event though the http status code is 200 ie. the request is OK. Why is this? 回答1: The problem might be that the

Correct HTTP status code when resource is available but not accessible because of permissions

倾然丶 夕夏残阳落幕 提交于 2019-11-28 07:17:44
问题 I am building a RESTful protocol for Dynamic Carpooling applications, for my Computer Science thesis. In the Protocol I also have to formally specify the HTTP status code for each operation. I've got this "privacy related" problem. Suppose the following: GET /api/persons/angela/location Retrieves the current position of user "angela". It is obvious that not everybody should be able to obtain a result. Only angela itself and a possible driver that is going to pick her should be able to know it