Comments (7)
What are the benefits of having the HTTP response status also in the JSON, I wonder?
The Link to more information seems useful, although it being a comma-separated string rather than an array seems odd.
I'm not sure of the use-case for the userMessage
– normally it's down to the developer to interpret error codes and present a user-interface, and I'm not sure I'd ever want to simply pass on a message from an API. Writing different messages for developers vs users seems like a bit of an anti-pattern too (as both should be equally clearly written).
from http-api-design.
The benefit I could see to having the HTTP status code in the JSON is that you don't have to breakout into the header data to get the code; it's there with the rest of your error data, but it probably is unnecessary overhead.
I'm not sure I understand the "Use three simple, common response codes", are they suggesting to use only 200, 400, 500 to the exclusion of more descriptive status codes like 201, 401, 507? If I'm reading that correctly then I can't see any reason for it, as a developer can choose to treat all 5 series status codes in the same way if they wish, while other developers may want to recover or behave in a different way based on the specific code returned. Providing a less descriptive code benefits neither.
from http-api-design.
Good feedback. I kind of liked the user vs developer messaging, as I've seen that sort of thing. At Heroku we might use user messages, for instance, in CLI responses or from the dashboard. Basically, that message is helpful if you have 3rd party users you are presenting info to. It makes sense to word it a bit different, basically you expect the developer might be able to change/do something about it, so instructing them on how to fix the issue makes sense. For a 3rd party user, however, you can often only explain simply and/or be apologetic. So kind of simple/apologetic vs complex/instructional or something.
I agree that the comma separated more-info is weird, though have a link of some sort there could be helpful (I'm not sure I would have a value handy for this purpose a lot of the time).
Including status there does seem a bit weird/redundant, I'd probably leave it out.
Similarly I think I prefer something like an error type string to just an integer to help developers know exactly whats up, ie unprocessable_entity
or something, maybe even more specific like invalid_email
in some cases. Basically the user shouldn't have to parse/compare against the developer/user strings (which might change) to figure out the specifics.
I'm definitely more of a fan of more status codes (where it makes sense to do so).
So, upon review, maybe I don't really like this example... I think it was probably at least helpful to dig in/consider/discuss though. What do you guys think?
from http-api-design.
@geemus the usefulness of the HTTP integer codes is that you can do some reasoning with them, e.g. matching 5xx
or 4xx
to work out if it's a server error or client error (useful as a fallback if the code isn't in your list of expected ones).
from http-api-design.
@frankieroberto For sure. I guess I just didn't see value in having that in headers AND body, vs just headers. Does that make more sense?
from http-api-design.
@geemus agreed – just using the headers seems most sensible to me (avoids the problem of the two codes accidentally contradicting each other).
from http-api-design.
@frankieroberto that's what I meant by overhead. Semantically I think it makes sense to leave it out also, the http header should provide enough information (i.e an appropriate status code) to determine there's been an error and the kind of error, the error message object is just an added convenience.
I definitely like the user and developer messages.
from http-api-design.
Related Issues (20)
- uuid in doubt HOT 4
- Dead link in about section HOT 1
- Guidance on implementing REST interfaces for state machine HOT 21
- I'm curious to know the reasoning for going with JSON Schemas instead of Swagger HOT 5
- How are you modeling authentication operation? HOT 1
- Using 409 Conflict for uniqueness checks HOT 2
- Create a website (Gitpage) HOT 3
- Traditional Chinese version, and add "List of Translations" HOT 5
- Consider adding language specific resources for implementing these principles HOT 1
- include more examples for main points HOT 9
- detail expansions
- Consider compatibility with jsonapi.org? HOT 8
- Why use UUID? HOT 12
- Paginating/ranging over non-unique fields HOT 15
- Pagination using Range cannot be consistent HOT 8
- Test Framework HOT 1
- The used time format is actually RFC5424, a subset of ISO8601 HOT 2
- Json with PLSQL ( PLJSON) HOT 1
- Links in README.md are 404 when viewed on Gitbook HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from http-api-design.