Bird
Raised Fist0
Rest APIprogramming~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of using the expand parameter in a REST API request?
easy
A. To delete related resources automatically
B. To include related resource data within the main resource response
C. To paginate the results of the API response
D. To filter the main resource by specific fields

Solution

  1. Step 1: Understand the expand parameter role

    The expand parameter is used to include related or nested resource data inside the main resource response.
  2. Step 2: Compare with other options

    Filtering, pagination, and deletion are different API features and not related to embedding data.
  3. Final Answer:

    To include related resource data within the main resource response -> Option B
  4. Quick Check:

    Expand = embed related data [OK]
Hint: Expand means embed related data inside main response [OK]
Common Mistakes:
  • Confusing expand with filtering or pagination
  • Thinking expand deletes data
  • Assuming expand changes data instead of embedding
2. Which of the following is the correct syntax to expand the 'author' field in a REST API GET request URL?
easy
A. /posts?expand=author
B. /posts?embed=author
C. /posts?include=author
D. /posts?fields=author

Solution

  1. Step 1: Identify the standard parameter for resource expansion

    The common parameter to embed related data is expand.
  2. Step 2: Check the URL syntax

    The correct syntax uses ?expand=author to embed the author data inside posts.
  3. Final Answer:

    /posts?expand=author -> Option A
  4. Quick Check:

    Use expand=field to embed [OK]
Hint: Use ?expand=resourceName to embed related data [OK]
Common Mistakes:
  • Using embed or include instead of expand
  • Using fields which filters fields, not expands
  • Missing the question mark before parameters
3. Given the API endpoint /orders?expand=customer, what will the response include?
medium
A. A list of customers unrelated to orders
B. Only order details without customer info
C. Only customer information without orders
D. Order details with embedded customer information

Solution

  1. Step 1: Analyze the expand parameter usage

    The parameter expand=customer tells the API to include customer data inside each order.
  2. Step 2: Understand the response content

    The response will contain order details plus the related customer information embedded.
  3. Final Answer:

    Order details with embedded customer information -> Option D
  4. Quick Check:

    Expand=customer means embed customer data [OK]
Hint: Expand embeds related resource data inside main response [OK]
Common Mistakes:
  • Expecting only orders without customer info
  • Thinking expand replaces main resource
  • Confusing expand with filtering or unrelated data
4. You tried to expand the 'comments' field with /posts?expand=comments but the API returns an error. What is the most likely cause?
medium
A. The 'comments' field is not a valid expandable resource
B. The API requires POST method for expansion
C. The expand parameter should be 'include' instead
D. The URL is missing a trailing slash

Solution

  1. Step 1: Check if 'comments' is expandable

    Not all fields can be expanded; the API must support expanding 'comments'.
  2. Step 2: Verify HTTP method and parameter correctness

    Expansion usually works with GET and uses 'expand', so POST or 'include' are unlikely causes.
  3. Step 3: URL format check

    Missing trailing slash usually does not cause expansion errors.
  4. Final Answer:

    The 'comments' field is not a valid expandable resource -> Option A
  5. Quick Check:

    Expandable fields must be supported by API [OK]
Hint: Check if field supports expand before using it [OK]
Common Mistakes:
  • Using wrong HTTP method for expansion
  • Confusing expand with include parameter
  • Assuming all fields are expandable
5. You want to get a list of invoices with embedded customer and payment details in one API call. Which URL correctly uses resource expansion for both related resources?
hard
A. /invoices?embed=customer,payment
B. /invoices?expand=customer&expand=payment
C. /invoices?expand=customer,payment
D. /invoices?expand=customer;payment

Solution

  1. Step 1: Understand how to expand multiple resources

    Multiple expansions are usually comma-separated in a single expand parameter.
  2. Step 2: Evaluate each option's syntax

    /invoices?expand=customer,payment uses comma-separated values correctly. /invoices?expand=customer&expand=payment repeats the parameter which is often unsupported. /invoices?embed=customer,payment uses 'embed' which is incorrect. /invoices?expand=customer;payment uses semicolon which is not standard.
  3. Final Answer:

    /invoices?expand=customer,payment -> Option C
  4. Quick Check:

    Multiple expands separated by commas [OK]
Hint: Use commas to expand multiple resources in one parameter [OK]
Common Mistakes:
  • Repeating expand parameter multiple times
  • Using embed instead of expand
  • Separating resources with semicolons
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard