Given an API endpoint /orders?expand=customer that returns orders with embedded customer data, what will be the customer name in the first order?
{
"orders": [
{
"id": 101,
"total": 250,
"customer": {
"id": 1,
"name": "Alice Smith"
}
},
{
"id": 102,
"total": 150,
"customer": {
"id": 2,
"name": "Bob Jones"
}
}
]
}Resource expansion embeds related data inside the main resource.
The expand=customer query parameter includes the full customer object inside each order. The first order's customer name is "Alice Smith".
What is the main benefit of using resource expansion (embedding related data) in REST API responses?
Think about how many requests a client must make to get all needed data.
Embedding related data reduces the number of calls a client must make, improving efficiency and user experience.
An API call to /products?expand=category returns:
{
"products": [
{"id": 10, "name": "Pen", "category": 3}
]
}Why is the category data not embedded?
Check if the API supports expansion for the requested field.
If the API does not support expansion for a field, the related data will not be embedded even if requested.
You want to expand both author and comments in a REST API call. Which query string is correct?
Multiple expansions are usually comma-separated in one parameter.
The standard way to request multiple expansions is to list them comma-separated in the expand parameter.
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?
Add the orders from all users.
The total embedded orders are 2 + 0 + 1 = 3.