SK176H SK176H - 7 months ago 54
reST (reStructuredText) Question

Multiple instances of REST Assured

Is there a way I can have multiple instances of Rest Assured Client.

I have to test two different endpoints that need

  1. Different serializers and deserializers

  2. Different headers and content types

how can I achieve that. I think Rest Assured is really good but I am severely limited by its globalness

Are there any design patterns that I can used to get away from this limitation ?


If you don't apply any global configuration statically you can create two different RequestSpecifications. For example:

RequestSpecification spec1 = new RequestSpecBuilder().addHeader("x", "1").setContentType("application/xml").config(RestAssured.config().objectMapperConfig(objectMapperConfig().defaultObjectMapper(..)).build();
RequestSpecification spec2 = new RequestSpecBuilder().addHeader("y", "2").setContentType("application/json").config(RestAssured.config().objectMapperConfig(objectMapperConfig().defaultObjectMapper(..)).build();

// Endpoint 1
given().spec(spec1). ..
// Endpoint 2
given().spec(spec2). ..