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"}}]}Look at the status code for the second operation in the response.
The second operation in the batch creates an order and returns status 201, which means 'Created'.
Composite operations allow clients to:
Think about how composite operations improve efficiency.
Composite operations bundle multiple related resource operations into one HTTP request, reducing network overhead and latency.
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?
Check the data type of userId in the second operation.
The userId should be a numeric ID, but "abc" is a string, causing a validation error and 400 Bad Request.
You want to create a composite operation that either completes all resource creations or none (all-or-nothing). Which approach is best?
Atomicity means all succeed or all fail together.
Server-side transactions ensure that if any operation in the batch fails, all changes are undone, preserving atomicity.
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?
Check how the second operation uses the first operation's result.
The second operation references the first operation's created project ID (42) dynamically, so the projectId is 42.