http-status-codes

Response status code for searches in REST APIs

一笑奈何 提交于 2019-11-27 15:06:52
Suppose, we have the following API: GET /api/guests/{id} GET /api/guests?name=dummy Which status code should I return when there are no guests matching criteria? I mean no guests with name dummy . Should it be 404 , 204 or 200 with an empty array? I would return 200 with an empty array... Or a 204 (No Content) A 404 is when a resource isn't found. Your resource in this case is the collection of guests... which exists. The proper status code for each situation Consider the following situations: GET /api/guests?name=dummy It's an operation that requests a representation of a collection. If no

PHP Get Content of HTTP 400 Response

自作多情 提交于 2019-11-27 14:26:32
I am using PHP with the Amazon Payments web service. I'm having problems with some of my requests. Amazon is returning an error as it should, however the way it goes about it is giving me problems. Amazon returns XML data with a message about the error, but it also throws an HTTP 400 (or even 404 sometimes). This makes file_get_contents() throw an error right away and I have no way to get the content. I've tried using cURL also, but never got it to give me back a response. I really need a way to get the XML returned regardless of HTTP status code. It has an important "message" element that

Why does Firebug show a “206 Partial Content” response on a video loading request?

微笑、不失礼 提交于 2019-11-27 13:38:20
I have a bunch of html5 video elements, with their preload attribute set to "auto". They start loading just fine, but I think there might be a problem with their caching, because each time I reload the page (without clearing the cache), they start all over again. When I checked the Network panel in firebug, I noticed everything else (images and files) was giving me a "304 not modified" message as espected, while the videos (and audio) files were giving me a "206 partial content" message, in duplicated entries. The "206 partial content" response also appears in duplicated entries when the page

Catch PHP Fatal Error

房东的猫 提交于 2019-11-27 13:05:51
问题 I have a web service site that is restful enabled, so other websites/ajax script can make a call to the site to get/set data. However, whenever the web service site somehow returns a PHP fatal error, the HTTP status that is returned is 200 instead of 500. Is there a way to fix it so that whenever a fatal error occurs, returns 500 instead of 200? Or, if it is not possible, how can I change my client to recognize the fatal error returned by the webservice? 回答1: One possible way would be to set

Is it wrong to return 202 “Accepted” in response to HTTP GET?

99封情书 提交于 2019-11-27 11:59:47
I have a set of resources whose representations are lazily created. The computation to construct these representations can take anywhere from a few milliseconds to a few hours, depending on server load, the specific resource, and the phase of the moon. The first GET request received for the resource starts the computation on the server. If the computation completes within a few seconds, the computed representation is returned. Otherwise, a 202 "Accepted" status code is returned, and the client must poll the resource until the final representation is available. The reason for this behavior is

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

三世轮回 提交于 2019-11-27 11:24:09
问题 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

HTTP 400 (bad request) for logical error, not malformed request syntax

非 Y 不嫁゛ 提交于 2019-11-27 11:00:37
The HTTP/1.1 specification (RFC 2616) has the following to say on the meaning of status code 400, Bad Request (§10.4.1) : The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications. There seems to be a general practice among a few HTTP-based APIs these days to use 400 to mean a logical rather than a syntax error with a request. My guess is that APIs are doing this to distinguish between 400 (client-induced) and 500 (server-induced). Is it acceptable or incorrect to use 400 to indicate non-syntactic errors? If it is

What is the appropriate HTTP status code response for a general unsuccessful request (not an error)?

别来无恙 提交于 2019-11-27 10:59:14
I'm creating a RESTful API that will process a number of user interactions, including placing orders using stored credit cards. In the case of a successful order, I'm returning a 200 OK, and in the case where the order request is malformed or invalid I'm returning a 400 Bad Request. But what should I return if there is a problem during the actual processing of the order? Client POSTS order to server for a user resource. If user does not exist, 404 Not Found is returned. Order format and information is validated. If not valid, 400 Bad Request is returned. Order is processed. If the order is

What's the difference between HTTP 301 and 308 status codes?

血红的双手。 提交于 2019-11-27 10:43:06
What's the difference between HTTP 301 and 308 status codes? 301 (Moved Permanently): This and all future requests should be directed to the given URI. 308 (Permanent Redirect): The request and all future requests should be repeated using another URI. They seem to be similar. An overview of 301 , 302 and 307 The RFC 7231 , the current reference for semantics and content of the HTTP/1.1 protocol, defines the 301 (Moved Permanently) and 302 (Found) status code, that allows the request method to be changed from POST to GET . This specification also defines the 307 (Temporary Redirect) status code

Laravel - Return json along with http status code

≡放荡痞女 提交于 2019-11-27 10:40:09
问题 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. 回答1: 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