SoftwareTestPilot
API TestingPublished: 14 min read

REST Assured Tutorial for Java QA (2026 Complete Guide)

Master REST Assured with 20 real examples: GET/POST/PUT/DELETE, JSON schema validation, auth, filters, and the framework layer that makes API tests survive a rewrite.

Avinash Kamble
Founder & QA Engineer at SoftwareTestPilot
Reviewed by Priyanka G.
Share:XLinkedInWhatsApp
REST Assured tutorial — Java API testing with 20 real examples.
REST Assured tutorial — Java API testing with 20 real examples.

Last updated 2026-07-20 · 14 min read · By Avinash Kamble, reviewed by Priyanka G.

REST Assured has been the JVM API testing default for a decade because it reads like English. This tutorial takes you from Maven setup to production-grade framework — authentication, schema validation, request specs, and CI wiring — with 20 examples you can lift directly.

Key takeaways

  • Maven and Gradle setup with the exact 2026 dependency versions.
  • 20 examples: CRUD, auth, headers, JSON schema, XML.
  • Given-When-Then DSL and how to keep specs DRY.
  • Wiring REST Assured into JUnit 5 and Allure for CI reports.

1. Maven setup

<dependency>
  <groupId>io.rest-assured</groupId>
  <artifactId>rest-assured</artifactId>
  <version>5.5.0</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>io.rest-assured</groupId>
  <artifactId>json-schema-validator</artifactId>
  <version>5.5.0</version>
</dependency>

Full setup and language options in the official REST Assured site.

2. The given-when-then DSL

import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;

given()
    .baseUri("https://api.example.com")
    .header("Authorization", "Bearer " + token)
.when()
    .get("/orders/4211")
.then()
    .statusCode(200)
    .body("id", equalTo(4211))
    .body("items.size()", greaterThan(0))
    .time(lessThan(500L));

3. Full CRUD examples

// POST
given().contentType("application/json")
       .body("{\"sku\":\"ABC\",\"qty\":2}")
   .when().post("/orders")
   .then().statusCode(201).body("id", notNullValue());

// PUT
given().contentType("application/json").body(updated)
   .when().put("/orders/4211")
   .then().statusCode(200);

// DELETE
when().delete("/orders/4211").then().statusCode(204);

// GET with query
given().queryParam("status", "shipped")
   .when().get("/orders")
   .then().body("size()", equalTo(12));

4. JSON Schema validation

import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;

when().get("/orders/4211")
   .then().body(matchesJsonSchemaInClasspath("schemas/order.json"));

Ship the schema in src/test/resources/schemas/. Cross-reference our JSON tester for exploring paths interactively.

5. RequestSpecification — keep it DRY

RequestSpecification api = new RequestSpecBuilder()
    .setBaseUri("https://api.example.com")
    .addHeader("Authorization", "Bearer " + token)
    .setContentType("application/json")
    .build();

given().spec(api).when().get("/orders/4211").then().statusCode(200);
given().spec(api).when().delete("/orders/4211").then().statusCode(204);

6. Wiring into JUnit 5 + Allure

Add allure-rest-assured, register filter(new AllureRestAssured()), and every request appears in the Allure report with headers, body, and timing. Publish the Allure artifact from GitHub Actions. Bridge to your API testing interview prep and the Postman tutorial cluster for cross-tool depth.

Frequently asked questions

1.REST Assured or Karate — which for a new Java team?
REST Assured for developer-heavy teams (Java everywhere); Karate for mixed teams that want BDD-style specs and built-in mocks.
2.Does REST Assured support GraphQL?
Yes, as raw POST requests to /graphql. It won't parse the schema but you can validate the response with JSON Schema Validator.
3.How do I run REST Assured tests in parallel?
Use JUnit 5 parallel execution or TestNG parallel classes. REST Assured itself is stateless, so parallelism is safe.
4.Can I share a token across tests?
Yes — get the token in a @BeforeAll and store it in a static field or RequestSpecification builder.
Keep going

Practice these questions

Rehearse REST, Postman, REST Assured and contract-testing questions with worked examples.

Found this useful?
Share:XLinkedInWhatsApp

Was this article helpful?

Cluster · API Testing

More from REST API Testing

REST fundamentals — verbs, status codes, contracts.

Pillar guide · 36 articles
More in this cluster
From the API Testing pillar

Keep building your QA edge

Practice these questions live

Rehearse with an AI QA interviewer that scores your answers in real time.

Start a Free AI Mock Interview →

Continue reading

Topic mapConcepts · Tools · People · Standards

Related concepts, tools & standards around API Testing

A quick reference of the people, companies, frameworks and technologies most often mentioned alongside API Testing in real QA teams — useful when you're mapping a learning path, preparing for interviews, or scoping a new project.

Core testing concepts
OAuth 2.0JWT AuthenticationIdempotencyTest PyramidShift-Left TestingBehavior-Driven DevelopmentTest-Driven DevelopmentPage Object ModelContract TestingExploratory Testing
Programming languages
JavaPythonJavaScriptTypeScriptC#SQL
Certifications worth knowing
ISTQB Foundation LevelISTQB Advanced — Test AnalystISTQB Agile TesterCertified Selenium ProfessionalAWS Certified DevOps EngineerCertified ScrumMaster (CSM)
Companies hiring for this skill
GoogleMicrosoftAmazonMetaNetflixAtlassianThoughtWorksInfosysTCSWipro

Discussion

Ask a question, share your experience, or correct us. Be kind — real people are reading.

Join the QA Community

Connect with fellow testers, share job leads, and get career advice.

Premium QA Resources

Stop Reinventing the Wheel. Upgrade Your QA Arsenal.

Take your testing skills from beginner to Lead Engineer. Supercharge your daily workflow with our premium digital resources.

  • Ready-to-use testing strategy templates
  • Advanced API & UI automation guides
  • ⏱️ Save 10+ hours a week on test planning
4.9/5 rating
Explore All Products

⭐⭐⭐⭐⭐ Trusted by 1,000+ Software Test Pilots • Instant Access