0
0
Rest APIprogramming~20 mins

Request body structure in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Request Body 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 request body?
Given this JSON request body sent to an API, what is the value of the "totalPrice" field after the server calculates it?
Rest API
{
  "items": [
    {"name": "apple", "quantity": 2, "price": 3},
    {"name": "banana", "quantity": 1, "price": 1}
  ],
  "totalPrice": 0
}
A7
B6
C5
D0
Attempts:
2 left
💡 Hint
Multiply quantity by price for each item and add them up.
🧠 Conceptual
intermediate
1:00remaining
Which HTTP method usually requires a request body?
Choose the HTTP method that typically sends data in the request body to create or update resources.
AGET
BHEAD
CDELETE
DPOST
Attempts:
2 left
💡 Hint
Think about sending new data to the server.
🔧 Debug
advanced
2:00remaining
What error will this JSON request body cause?
This JSON request body is sent to an API expecting a list of users. What error will the server likely return?
Rest API
{
  "users": {
    "name": "Alice",
    "age": 30
  }
}
AKeyError: 'users' not found
BSyntaxError: Invalid JSON format
CTypeError: Expected a list but got an object
DNo error, processed successfully
Attempts:
2 left
💡 Hint
The server expects a list but got a single object.
📝 Syntax
advanced
1:30remaining
Which JSON request body is syntactically correct?
Select the JSON request body that is valid and can be parsed without errors.
A{ user: { name: "Bob", age: 25 } }
B{ "user": { "name": "Bob", "age": 25 } }
C{ "user": { "name": "Bob", "age": 25, }
D{ "user": { "name": "Bob", "age": 25 }, }
Attempts:
2 left
💡 Hint
Look for trailing commas and missing quotes.
🚀 Application
expert
1:00remaining
How many items are in the 'products' list in this JSON request body?
Count the number of product objects inside the 'products' array in this JSON request body.
Rest API
{
  "products": [
    {"id": 1, "name": "Pen"},
    {"id": 2, "name": "Notebook"},
    {"id": 3, "name": "Eraser"},
    {"id": 4, "name": "Ruler"}
  ]
}
A4
B5
C3
D2
Attempts:
2 left
💡 Hint
Count each object inside the square brackets.