0
0
Rest APIprogramming~20 mins

Composite operations (multi-resource) in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Composite Operations 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 composite REST API call?

Consider a REST API that supports batch requests to create multiple resources in one call. The batch request payload is:

{"operations": [{"method": "POST", "path": "/users", "body": {"name": "Alice"}}, {"method": "POST", "path": "/orders", "body": {"userId": 1, "product": "Book"}}]}

If the API returns the following response, what is the value of response.operations[1].status?

{"operations": [{"status": 201, "body": {"id": 1, "name": "Alice"}}, {"status": 201, "body": {"id": 101, "userId": 1, "product": "Book"}}]}
A400
B201
C404
D500
Attempts:
2 left
💡 Hint

Look at the status code for the second operation in the response.

🧠 Conceptual
intermediate
1:30remaining
Which statement best describes composite operations in REST APIs?

Composite operations allow clients to:

ACache responses locally to avoid repeated API calls.
BExecute only one resource operation per HTTP request to ensure atomicity.
CSend multiple related requests in a single HTTP call to reduce network overhead.
DUse WebSockets instead of HTTP for faster communication.
Attempts:
2 left
💡 Hint

Think about how composite operations improve efficiency.

🔧 Debug
advanced
2:30remaining
Identify the error in this composite operation request payload

Given this JSON payload for a composite REST API call:

{"operations": [{"method": "POST", "path": "/users", "body": {"name": "Bob"}}, {"method": "POST", "path": "/orders", "body": {"userId": "abc", "product": "Pen"}}]}

What error will the API most likely return?

A400 Bad Request due to invalid userId type
B404 Not Found because /orders path is incorrect
C500 Internal Server Error due to server crash
D201 Created for both operations
Attempts:
2 left
💡 Hint

Check the data type of userId in the second operation.

🚀 Application
advanced
3:00remaining
How to ensure atomicity in composite REST API operations?

You want to create a composite operation that either completes all resource creations or none (all-or-nothing). Which approach is best?

AUse a transaction mechanism on the server that rolls back all changes if any operation fails.
BSend operations sequentially and ignore failures in intermediate steps.
CSend all operations in parallel without rollback support.
DUse client-side retries to fix failed operations after the batch completes.
Attempts:
2 left
💡 Hint

Atomicity means all succeed or all fail together.

Predict Output
expert
3:00remaining
What is the final state after this composite operation with dependencies?

Consider a composite REST API call with two operations:

{"operations": [{"id": "op1", "method": "POST", "path": "/projects", "body": {"name": "ProjectX"}}, {"id": "op2", "method": "POST", "path": "/tasks", "body": {"projectId": "${op1.body.id}", "title": "Task1"}}]}

If the server processes these operations and returns:

{"operations": [{"id": "op1", "status": 201, "body": {"id": 42, "name": "ProjectX"}}, {"id": "op2", "status": 201, "body": {"id": 101, "projectId": 42, "title": "Task1"}}]}

What is the value of response.operations[1].body.projectId?

Anull
B"${op1.body.id}"
C101
D42
Attempts:
2 left
💡 Hint

Check how the second operation uses the first operation's result.