Each microservice's API should return the data in the same way, defined below:
- The API should be RESTful (see here about the REST)
- The API should return the standard HTTP response codes depending on the result. (Example: return '200 OK' after the objects listing, return '201 Created' after the object creation, return '404 Not Found' if the object was not found etc.)
- The JSON response should have the same structure (see below).
Response structure
Each response should have the same structure, depending on the request and the result.
The response structures for the successful and unsuccessful request are slightly different.
Successful response
{
"success": true,
"meta": {},
"data": [],
"message": "A message to user."
}
|
- success - Mandatory field. that represents if the API call was successful or not. Should always be true for the successful call.
- data - Optional field. containing 1 or more object requested/modified/deleted by user.
- message - Optional field. A string containing a message to the user, useful on POST/PUT/DELETE requests.
Unsuccessful response
{
"success": false,
"errors": [],
"message": "An error has occured."
} |
- success - Mandatory field. A boolean that represents if the API call was successful or not. Should always be false for the unsuccessful call.
- errors - Optional field. An array containing errors' details, if available. (e.g. validation errors)
- message - Mandatory field. A string containing an error message.