http-status-codes

JAX-RS — How to return JSON and HTTP status code together?

让人想犯罪 __ 提交于 2019-11-26 03:32:26
问题 I\'m writing a REST web app (NetBeans 6.9, JAX-RS, TopLink Essentials) and trying to return JSON and HTTP status code. I have code ready and working that returns JSON when the HTTP GET method is called from the client. Essentially: @Path(\"get/id\") @GET @Produces(\"application/json\") public M_機械 getMachineToUpdate(@PathParam(\"id\") String id) { // some code to return JSON ... return myJson; } But I also want to return an HTTP status code (500, 200, 204, etc.) along with the JSON data. I

What's an appropriate HTTP status code to return by a REST API service for a validation failure?

萝らか妹 提交于 2019-11-26 03:01:20
问题 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 405 Method Not Allowed 406 Not Acceptable 412 Precondition Failed 417 Expectation Failed 422 Unprocessable Entity 424 Failed Dependency Update : \"Validation

400 vs 422 response to POST of data

一曲冷凌霜 提交于 2019-11-26 02:27:08
问题 I\'m trying to figure out what the correct status code to return on different scenarios with a \"REST-like\" API that I\'m working on. Let\'s say I have a end point that allows POST\'ing purchases in JSON format. It looks like this: { \"account_number\": 45645511, \"upc\": \"00490000486\", \"price\": 1.00, \"tax\": 0.08 } What should I return if the client sends me \"sales_tax\" (instead of the expected \"tax\"). Currently, I\'m returning a 400. But, I\'ve started questioning myself on this.

HTTP status code for update and delete?

被刻印的时光 ゝ 提交于 2019-11-26 02:26:18
问题 What status code should I set for UPDATE ( PUT ) and DELETE (e.g. product successfully updated)? 回答1: For a PUT request: HTTP 200 or HTTP 204 should imply "resource updated successfully". For a DELETE request: HTTP 200 or HTTP 204 should imply "resource deleted successfully". HTTP 202 can also be returned which would imply that the instruction was accepted by the server and the "resource was marked for deletion". PUT If an existing resource is modified, either the 200 (OK) or 204 (No Content)

What is the difference between HTTP status code 200 (cache) vs status code 304?

大憨熊 提交于 2019-11-26 01:55:56
问题 I\'m using the Google \"Page Speed\" plug-in for Firefox to access my web site. Some of the components on my page is indicated as HTTP status: 200 200 (cache) 304 By Google\'s \"Page Speed\". What I\'m confused about is the difference between 200 (cache) and 304. I\'ve refreshed the page multiple times (but have not cleared my cache) and it always seems that my favicon.ico and a few images are status=200 (cache) while some other images are http status 304. I don\'t understand why the

REST HTTP status codes for failed validation or invalid duplicate

北城余情 提交于 2019-11-26 00:21:14
问题 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 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? 回答1: For input validation failure: 400 Bad Request + your optional description

Why is AJAX returning HTTP status code 0?

∥☆過路亽.° 提交于 2019-11-25 23:20:41
问题 For some reason, while using AJAX (with my dashcode developed application) the browser just stops uploading and returns status codes of 0 . Why does this happen? 回答1: Another case: It could be possible to get a status code of 0 if you have sent an AJAX call and a refresh of the browser was triggered before getting the AJAX response . The AJAX call will be cancelled and you will get this status. 回答2: In my experience, you'll see a status of 0 when: doing cross-site scripting (where access is

403 Forbidden vs 401 Unauthorized HTTP responses

一曲冷凌霜 提交于 2019-11-25 21:57:40
问题 For a web page that exists, but for which a user that does not have sufficient privileges, (they are not logged in or do not belong to the proper user group), what is the proper HTTP response to serve? 401? 403? Something else? What I\'ve read on each so far isn\'t very clear on the difference between the two. What use cases are appropriate for each response? 回答1: A clear explanation from Daniel Irvine: There's a problem with 401 Unauthorized , the HTTP status code for authentication errors.