Back to Rest Assured

README

README.md

latest4.6 KB
Original Source

<!-- [![Javadoc](https://javadoc-badge.appspot.com/io.rest-assured/rest-assured.svg)](http://www.javadoc.io/doc/io.rest-assured/rest-assured) -->

Testing and validation of REST services in Java is harder than in dynamic languages such as Ruby and Groovy. REST Assured brings the simplicity of using these languages into the Java domain.

News

  • 2026-01-16: REST Assured 5.5.7 is released with backported support for Spring framework 7 MockMvc support. See change log for more details.
  • 2025-12-12: REST Assured 6.0.0 is released. It raises the baseline to Java 17+, upgrades to Groovy 5, adds Spring 7 + Jackson 3 support (and bumps minimum versions for Spring/Yasson/Johnzon). See release notes and change log for more details.
  • 2025-08-15: REST Assured 5.5.6 is released with bug fixes and minor improvements. See change log for more details.

Older News

Examples

Here's an example of how to make a GET request and validate the JSON or XML response:

java
get("/lotto").then().assertThat().body("lotto.lottoId", equalTo(5));

Get and verify all winner ids:

java
get("/lotto").then().assertThat().body("lotto.winners.winnerId", hasItems(23, 54));

Using parameters:

java
given().
    param("key1", "value1").
    param("key2", "value2").
when().
    post("/somewhere").
then().
    body(containsString("OK"));

Using X-Path (XML only):

java
given().
    params("firstName", "John", "lastName", "Doe").
when().
    post("/greetMe").
then().
    body(hasXPath("/greeting/firstName[text()='John']")).

Need authentication? REST Assured provides several authentication mechanisms:

java
given().auth().basic(username, password).when().get("/secured").then().statusCode(200);

Getting and parsing a response body:

java
// Example with JsonPath
String json = get("/lotto").asString();
List<String> winnerIds = from(json).get("lotto.winners.winnerId");
    
// Example with XmlPath
String xml = post("/shopping").andReturn().body().asString();
Node category = from(xml).get("shopping.category[0]");

REST Assured supports any HTTP method but has explicit support for POST, GET, PUT, DELETE, OPTIONS, PATCH and HEAD and includes specifying and validating e.g. parameters, headers, cookies and body easily.

Documentation

Support and discussion

Join the mailing list at our Google group.

<a href="https://www.buymeacoffee.com/johanhaleby" target="_blank"></a>