0
0
Rest APIprogramming~20 mins

Resource expansion (embed related data) in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Resource Expansion 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 REST API call with resource expansion?

Given an API endpoint /orders?expand=customer that returns orders with embedded customer data, what will be the customer name in the first order?

Rest API
{
  "orders": [
    {
      "id": 101,
      "total": 250,
      "customer": {
        "id": 1,
        "name": "Alice Smith"
      }
    },
    {
      "id": 102,
      "total": 150,
      "customer": {
        "id": 2,
        "name": "Bob Jones"
      }
    }
  ]
}
A"null"
B"Bob Jones"
C"Customer data not included"
D"Alice Smith"
Attempts:
2 left
💡 Hint

Resource expansion embeds related data inside the main resource.

🧠 Conceptual
intermediate
1:30remaining
Why use resource expansion in REST APIs?

What is the main benefit of using resource expansion (embedding related data) in REST API responses?

AIt reduces the number of API calls needed to get related data.
BIt makes the API response smaller in size.
CIt hides related data from the client.
DIt forces clients to request related data separately.
Attempts:
2 left
💡 Hint

Think about how many requests a client must make to get all needed data.

🔧 Debug
advanced
2:30remaining
Why does this API response fail to include expanded data?

An API call to /products?expand=category returns:

{
  "products": [
    {"id": 10, "name": "Pen", "category": 3}
  ]
}

Why is the category data not embedded?

AThe API does not support the <code>expand</code> parameter for categories.
BThe client forgot to include <code>expand=category</code> in the request.
CThe category field is a number, so expansion is automatic.
DThe server returned a syntax error.
Attempts:
2 left
💡 Hint

Check if the API supports expansion for the requested field.

📝 Syntax
advanced
1:30remaining
Which query string correctly requests multiple expansions?

You want to expand both author and comments in a REST API call. Which query string is correct?

A/posts?expand=author;comments
B/posts?expand=author&comments
C/posts?expand=author,comments
D/posts?expand=[author,comments]
Attempts:
2 left
💡 Hint

Multiple expansions are usually comma-separated in one parameter.

🚀 Application
expert
2:00remaining
How many items are in the expanded response list?

An API call to /users?expand=orders returns 3 users. Each user has a different number of orders:

  • User 1 has 2 orders
  • User 2 has 0 orders
  • User 3 has 1 order

How many total order objects are embedded in the response?

A0
B3
C1
D2
Attempts:
2 left
💡 Hint

Add the orders from all users.