♻️ H5 · Removing Duplication with RequestSpecification
H5 · Removing Duplication with: `RequestSpecification` is the **Page Object Model** counterpart in API testing: just as Selenium gathers locators for a page into ONE class to avo
`RequestSpecification` is the **Page Object Model** counterpart in API testing: just as Selenium gathers locators for a page into ONE class to avoid duplication, `RequestSpecification` gathers information repeated across every test — `baseUri`, common headers (`Content-Type`), auth token — into ONE place. Every test in H1-H4 wrote the `given().baseUri("http://localhost:3000")` line OVER AND OVER — if `baseUri` changes (e.g. moving to staging), EVERY test file would need manual updating. So why is this more than just a "shortcut"? Because duplicated setup code is a source of "silent divergence" like the one in F5 — if `baseUri` is updated in one test and FORGOTTEN in another, tests SILENTLY start running against different environments. **For a deep RequestSpecification guide → see the `/rest-assured` page.**
🎬 API Testing's Page Object Model
Setup repeated in every test
RequestSpecification
Setup managed from one place
Every test in H1-H4 wrote the SAME `baseUri`/header setup over and over.
This repetition is MOVED into a `RequestSpecification` class — just like moving locators into a Page Object in Selenium.
Now if `baseUri` changes, ONE place (BugApiSpec) is updated, ALL tests automatically hit the right environment.
The Order for Removing Duplication
Notice the duplication…
Observe the same baseUri/header/token lines written in every test.
Gather the common setup into ONE class with RequestSpecBuilder.
Share the SAME setup in every test with given().spec(BugApiSpec.spec()).
Order the process for extracting a RequestSpecification.