How do you add a header to a RestAssured request?
A) header()
B) addHeader()
C) withHeader()
D) setHeader()
Answer:
A) header()
Explanation:
The header()
method in RestAssured is used to add a header to an HTTP request. Headers provide additional context and metadata for the request.
For example:
import static io.restassured.RestAssured.*;
given().
header("Authorization", "Bearer token").
when().
get("/api/resource").
then().
statusCode(200);
In this example, the header()
method adds an “Authorization” header with a bearer token to the GET request.