Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

Http Code In response Json is useless #44

Open
akulubala opened this issue Nov 18, 2015 · 3 comments
Open

Http Code In response Json is useless #44

akulubala opened this issue Nov 18, 2015 · 3 comments

Comments

@akulubala
Copy link

this is really useless

@akulubala akulubala changed the title Why Http Code In response Json? Http Code In response Json is useless Nov 18, 2015
@maxtotterman
Copy link

In the error handler?
Is it really though? It aint much work to return a number and it is a nice way of reading status quickly, rather than open up network tab and check which status was sent imo.

@inadarei
Copy link

I would second this. HTTP protocol clearly has semantics for returning HTTP Error code and it is not in the payload. If I understand correctly this standard is trying to capture the common best practices of "pragmatic REST". It is not common or a best practice to have HTTP response code in the payload (e.g. JSON). Payload of an error condition should provide additional information.

As for the browser argument, Max provided – I think it would make sense if APIs were for humans (they are not) and also: in my experience most people who work with APIs either:

  1. realize that browsers cannot do many other things besides easily showing headers (e.g.: make PUT and DELETE requests) and opt to use a more appropriate tool, such as Postman
  2. employee more user-friendly interfaces to explore APIs, such as: Swagger.

@akulubala
Copy link
Author

@maxtotterman ,from client side, like ajax ,they have method to get http code, example: 5xx error, Server side error,retry request or implement a logic to deal with server side error,4xx error,mostly is client side input error, like params validate failed.2xx means request success. Restful api is use http status code to deal with program logics, no need to add an extra http code in response body.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@inadarei @maxtotterman @akulubala and others