0
0
Rest APIprogramming~10 mins

Composite operations (multi-resource) in Rest API - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Composite operations (multi-resource)
Start Composite Operation
Call API 1: Create Resource A
Check API 1 Success?
NoRollback if needed
Yes
Call API 2: Update Resource B
Check API 2 Success?
NoRollback API 1
Yes
Call API 3: Delete Resource C
Check API 3 Success?
NoRollback API 1 & 2
Yes
All Success
End
The composite operation calls multiple APIs in order, checking success after each. If any fail, it rolls back previous changes to keep data consistent.
Execution Sample
Rest API
POST /resourceA
if success:
  PATCH /resourceB
  if success:
    DELETE /resourceC
    if success:
      return success
    else:
      rollback resourceA and resourceB
  else:
    rollback resourceA
else:
  return error
This code tries to create, update, then delete resources in sequence, rolling back if any step fails.
Execution Table
StepAPI CalledRequestResponseSuccess?Action Taken
1POST /resourceACreate Resource A201 CreatedYesProceed to next API
2PATCH /resourceBUpdate Resource B200 OKYesProceed to next API
3DELETE /resourceCDelete Resource C500 Internal Server ErrorNoRollback resourceA and resourceB
4RollbackDELETE /resourceA, PATCH rollback /resourceB200 OKYesComposite operation ends with error
💡 Step 3 failed, so rollback was triggered to undo previous changes.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
resourceA_statusnonecreatedcreatedrollback startedrolled back
resourceB_statusnonenoneupdatedrollback startedrolled back
resourceC_statusexistsexistsdelete failedexistsexists
operation_statuspendingpendingpendingfailedfailed
Key Moments - 2 Insights
Why do we rollback resourceA and resourceB after resourceC deletion fails?
Because the composite operation must keep data consistent. The execution_table shows step 3 failed, so rollback undoes previous successful steps to avoid partial changes.
What happens if the first API call fails?
The composite operation stops immediately without calling other APIs, as shown in the concept_flow where failure at API 1 leads directly to end with error.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the response of the PATCH /resourceB call at step 2?
A500 Internal Server Error
B201 Created
C200 OK
D404 Not Found
💡 Hint
Check the Response column in row for step 2 in execution_table.
At which step does the composite operation decide to rollback?
AStep 3
BStep 1
CStep 2
DStep 4
💡 Hint
Look at the Success? column and Action Taken for step 3 in execution_table.
If the DELETE /resourceC call succeeded, what would be the final operation_status?
Afailed
Bsuccess
Cpending
Drollback started
💡 Hint
Refer to variable_tracker and concept_flow where all success leads to operation end with success.
Concept Snapshot
Composite operations call multiple APIs in order.
Each step checks success before continuing.
If any step fails, rollback undoes previous changes.
This keeps data consistent across resources.
Useful for multi-resource updates in REST APIs.
Full Transcript
Composite operations in REST APIs involve calling multiple API endpoints one after another. After each call, the system checks if it succeeded. If a call fails, the system rolls back any previous successful changes to keep data consistent. For example, creating resource A, updating resource B, and deleting resource C happen in sequence. If deleting resource C fails, the system undoes the creation and update to avoid partial changes. This process ensures all-or-nothing behavior across multiple resources.