Consider this API response envelope pattern:
{
"status": "success",
"data": {
"user": {
"id": 101,
"name": "Alice"
}
},
"error": null
}What will be the value of error in this response?
Look carefully at the value type of error in the JSON.
The error field is set to null which is a JSON null value, not a string or empty object.
Which of the following is the main reason to use a response envelope pattern in REST APIs?
Think about how metadata and data are organized in the response.
Response envelopes separate metadata (status, errors) from the main data, making responses consistent and easier to handle.
Here is a JSON response envelope from an API:
{
"status": "error",
"data": null,
"error": {
"code": 404,
"message": "User not found"
}
}What is wrong with this response if the HTTP status code is also 404?
Think about how error information is represented in the envelope and HTTP status.
It is valid to return HTTP 404 with an error envelope showing the error details and data as null.
Choose the syntactically correct JSON response envelope:
Remember JSON syntax rules for null and values.
Only option A uses valid JSON syntax with null for no error. Options A, C, and D are invalid JSON.
Given this JSON response envelope:
{
"status": "success",
"data": {
"users": [
{"id": 1, "name": "Anna"},
{"id": 2, "name": "Ben"},
{"id": 3, "name": "Cara"}
],
"count": 3
},
"error": null
}How many user objects are inside the data.users array?
Count the number of objects inside the users array.
The users array contains exactly 3 user objects.