← Back to libraryQuestion 244 of 468
🔌REST AssuredIntermediate

Chaining Requests — Using a Response in the Next Call

📌 Definition:

Real API workflows depend on prior responses: create a resource, extract its id/token, and use it in the next request. REST Assured enables this by extracting values and passing them forward.

📖 Detailed Explanation:

The pattern is extract-then-reuse: capture a value (String token / int id = ...then().extract().path(...)) and feed it into the subsequent request's header, path param, or body. This models end-to-end flows: login → token → protected call; create order → id → get/update/delete order. Keep each step's assertions (status/body) so a failure is localized. For readability, wrap common steps (login) in helper methods or specs. Managing test data across chained calls (and cleaning it up in teardown) is key to reliable, independent workflow tests.

🔑 Key Points:
  • Extract a value from one response, use it in the next request
  • Common flows: login→token, create→id→get/update/delete
  • Assert at each step so failures are localized
  • Clean up created data in teardown for independence
🌍 Real-World Example:

End-to-end order test: POST /orders → extract id → GET /orders/{id} (verify) → DELETE /orders/{id} (cleanup) — each step reusing the id from creation, forming a complete lifecycle test.

🎯 Scenario-Based Interview Question:

You must test: create a user, then verify it via GET by the new id. How do you pass the id between the two REST Assured calls?