0
0
Rest APIprogramming~20 mins

Response envelope patterns in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Response Envelope Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this JSON response envelope?

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?

A"null" (string)
BAn empty object {}
CAn empty string ""
Dnull (JSON null value)
Attempts:
2 left
💡 Hint

Look carefully at the value type of error in the JSON.

🧠 Conceptual
intermediate
2:00remaining
Why use a response envelope in REST APIs?

Which of the following is the main reason to use a response envelope pattern in REST APIs?

ATo separate metadata like status and errors from the actual data payload
BTo make the response smaller by removing metadata
CTo always return HTTP status 200 and put error info inside the envelope
DTo force clients to parse XML instead of JSON
Attempts:
2 left
💡 Hint

Think about how metadata and data are organized in the response.

🔧 Debug
advanced
2:00remaining
Identify the error in this response envelope example

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?

AThe <code>data</code> field should not be null when there is an error
BThe <code>status</code> field should be "success" even if HTTP status is 404
CThere is no error; this is a correct pattern
DThe HTTP status code should be 200 when using response envelopes
Attempts:
2 left
💡 Hint

Think about how error information is represented in the envelope and HTTP status.

📝 Syntax
advanced
2:00remaining
Which JSON response envelope is syntactically correct?

Choose the syntactically correct JSON response envelope:

A{ "status": "success", "data": { "id": 1, "name": "Bob" }, "error": null }
B{ "status": "success", "data": { "id": 1, "name": "Bob" }, "error": }
C{ "status": "success", "data": { "id": 1, "name": "Bob" }, "error": undefined }
D{ "status": "success", "data": { "id": 1, "name": "Bob" }, "error": None }
Attempts:
2 left
💡 Hint

Remember JSON syntax rules for null and values.

🚀 Application
expert
2:00remaining
How many items are in the 'data' field of this response envelope?

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?

A2
B3
C4
D0
Attempts:
2 left
💡 Hint

Count the number of objects inside the users array.