Skip to content

JSON API Boilerplate Tip

Michael Hulse edited this page Jul 16, 2018 · 5 revisions
Name Type Value
status int 0=success, 1=error, 2=failure. Success meaning everything went as expected. Error meaning that there was an actual error that occurred in the code or the database. And finally failure, meaning that while there was no syntactical, nor perhaps even logic error the operation could not be completed.
action String Informative potentially end user digestible suggestion of what to do next
message String A snippet extraordinarily well formatted English text which may or may not be digestible by an end user and will include error text should they occur

Example:

{
    "status": 1,
    "action": "Your request resulted in an error; did you forget to pass param1?",
    "message": "java.lang.IllegalArgumentException: 121",
    "data": [{}]
}

The above approach to status codes reminds me of shell exit codes:

Exit code 0        Success
Exit code 1        General errors, Miscellaneous errors, such as "divide by zero" and other impermissible operations
Exit code 2        Misuse of shell builtins (according to Bash documentation)

Lastly, here is a site that attempts to standardize these things:

Clone this wiki locally