How to verify JSON response headers in Rest Assured?

HOME

import org.junit.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.containsString;

public class ResponseHeader {

    @Test
    public void verifyResponseHeader() {

      // Given
      given()

              // When
              .when()
              .get("https://reqres.in/api/users/2")

              // Then
              .then()
              .statusCode(200).statusLine("HTTP/1.1 200 OK")
              .log().all()
              .header("Content-Type" , "application/json; charset=utf-8")
              .header("Content-Encoding" , "gzip")
              .header("Server" , containsString("cloudflare"));

    }
}

Leave a comment