krish
krish

Reputation: 369

Can we set more than one header using REST-Assured framework

I've a requirement that i need to set more than one header for a REST API using REST-Assured framework.

private static String buildHeader(){
    String header = "application/json; charset=UTF-8";
    return header;
}
/** This method is used to build a body for request specification**/
private static RequestSpecBuilder buildBody(JSONObject json) throws ConfigurationException, URISyntaxException, IOException{
    //JSONObject json = JsonData.getPostJSONData();
    String APIBody = json.toString();
    RequestSpecBuilder resBuilder = new RequestSpecBuilder();
    resBuilder.setBody(APIBody);
    resBuilder.setContentType(RequestBuilder.buildHeader());
    return resBuilder;
}

This is my code which is shown above. In this we can see that Im using a private build header and just returned a string. I set it as a content type to RequestSpecBuilder. So now, I've requirement that I need to set more than one header. Does anybody know how to do that?

Upvotes: 2

Views: 1447

Answers (1)

drez90
drez90

Reputation: 814

You can do it through the constructor

RequestSpecification resBuilder= new RequestSpecBuilder()
                    .setContentType(ContentType.JSON)
                    .addHeader("Auth", "my-auth")
                    .addHeader("X-API-Version", apiVersion))

Upvotes: 1

Related Questions