API testing
Start here when you want one REST call, one assertion, and request/response evidence in the same report as your browser and mobile tests.
import com.shaft.driver.SHAFT;
import org.testng.annotations.Test;
public class CountryApiTest {
@Test
public void getCountryByCapital() {
SHAFT.API api = new SHAFT.API("https://restcountries.com/v3.1/");
api.get("capital/Cairo").perform();
api.assertThatResponse()
.extractedJsonValue("[0].name.common")
.isEqualTo("Egypt");
}
}
Continue with request building, authentication, and response assertions. When the API is part of a browser journey, use UI and API contract replay to record the exchanged traffic once and assert or replay it later.
Run and inspect evidence
Run the test from the project root:
mvn test
SHAFT attaches request, response, status, headers, body, and assertion evidence
under allure-results and the generated Allure report under the project target output. If the request fails before assertions, check the
base URI, proxy settings, authentication, and whether automatic 2xx status
assertion is appropriate for the scenario.
First useful next steps
| Need | Start with |
|---|---|
| Add headers, query parameters, or body | Request Builder |
| Reuse tokens or basic auth | API Authentication |
| Validate JSON fields or schemas | Response Validations |
| Record and replay UI/API traffic | UI and API contract replay |
| Track OpenAPI coverage | API configuration |