# REST Assured practice API: check JSON data and HTTP 418

Learn to distinguish a valid business response from an intentionally unusual HTTP status. These read-only examples do not require authentication.

## Before you start

- An existing Java test project with REST Assured and JUnit Jupiter configured.
- Save the example in your test source folder as CoffeeApiTest.java and run your project test command.
- REST Assured uses Hamcrest matchers; use compatible dependencies in your existing project.

## Check a filtered JSON contract

The first test checks the status, content type and each drink type. The second expects the teapot endpoint to return HTTP 418.

```java
import org.junit.jupiter.api.Test;
import java.util.UUID;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;

class CoffeeApiTest {
  @Test void hotDrinksHaveTheExpectedType() {
    given().baseUri("https://funapi.dev/api")
      .header("X-Sandbox-ID", UUID.randomUUID().toString())
      .queryParam("type", "hot")
    .when().get("/coffee/v1/drinks")
    .then().statusCode(200).contentType("application/json")
      .body("data.size()", greaterThan(0))
      .body("data.type", everyItem(equalTo("hot")));
  }

  @Test void teapotStatusIsAnExpectedResult() {
    given().baseUri("https://funapi.dev/api")
      .header("X-Sandbox-ID", UUID.randomUUID().toString())
    .when().get("/coffee/v1/teapot")
    .then().statusCode(418);
  }
}
```

## Extend the validation boundary

Add GET /coffee/v1/drinks?type=warm and expect 400. Keep this separate from the valid hot/cold cases so a failure explains which contract changed.


## Expected result

The provided two tests pass: hot drinks return JSON with 200, and the teapot returns 418. The optional invalid type returns 400.

## Common pitfalls

- Place the class in your test source directory and ensure JUnit discovers it.
- An intentional 418 should not be rewritten as a 200 expectation.
- Use a fresh sandbox identifier for independent tests rather than a shared classroom value.
