I'm building a JSON REST API. Some of the API actions require attributes. In case a API request to those actions is made without all the required attributes, the API returns a 4xx HTTP code and the list of missing attributes in JSON format.
For now, this JSON response only contains an object with the "errors" k开发者_如何学编程ey storing an array of error messages. For example:
{"errors":["'first_name' attribute is missing","'title' attribute is missing"]}
So the API consumer just have to check if the "errors" key is null or contains an array of error messages.
Do you think that might be enough? This is a vague question, I'm looking for best/recommended practices to report such errors, to make the consuming of the API more natural and easy.
精彩评论