How to create base HTTP request with common query parameters

Hi. I am interested in defining a query parameter that will appear on every HTTP request that extends the trait where that query parameter is defined rather than added it individually on each simulation. How do I do that?

This would be similar to how Rest Assured allows you to merge RequestSpecifications in terms of the desired effect.

Thanks!

I am interested in defining a query parameter that will appear on every HTTP request that extends the trait where that query parameter is defined rather than added it individually on each simulation.

Sorry, I don’t understand what you mean (mixing requests and simulations).
Could you please provide an example of what you’re trying to achieve?

Hey Stephane. Where I am doing something like this where I am including uniqueCallId on each request, I want to extend or merge an existing http request that already has uniqueCallId on it:

val search =
exec(http("${entity}")
.get("${restURL}search/${entity}")
.header(“BhRestToken”, “${restToken}”)
.queryParam(“query”, queryString)
.queryParam(“count”, 15)
.queryParam(“uniqueCallId”, uniqueCallId)
.check(status.is(200))
)

Hi Mike
You can try something like this

trait HttpSupport {

def getHttpConf(implicit httpParam:HttpParam): HttpProtocolBuilder = {
http
.baseUrl(httpParam.baseURL)
.acceptHeader(“application/json”)
.basicAuth(httpParam.userName, httpParam.password)
.header(“Content-Type”, “application/json”)
.shareConnections
}

}

class extends Simulation with HttpSupport {
val httpConf = getHttpConf

httpConf.queryParam()


}

Thanks. Is it possible to add HTTP query parameters in the HttpProtocol? I didn’t think it was. Can you show an example of adding one?

You can try adding that to the trait method getHttpConf… and pass the query param values are parameters to the method

Still not sure what you’re trying to do, but:

  • no, there’s no way to define common queryParams on HttpProtocol
  • you could create a method to create your requests, eg:
    def makeRequest(name: String, url: String) =
    http(name).get(url).queryParam(“foo”, “bar”)

Then

exec(makeRequest(“name”, “url”).queryParam(“baz”, “qix”))

So far I haven’t been able to get anything like the suggestion to work. Any other ideas? Maybe I am just misunderstanding and need a more explicit example.

Here is the equivalent of what I want to do - in REST Assured:
spec
RequestSpecification spec(RequestSpecification requestSpecificationToMerge)
Add request data from a pre-defined specification. E.g. RequestSpecification requestSpec = new RequestSpecBuilder().addParam(“parameter1”, “value1”).build(); given(). spec(requestSpec). param(“parameter2”, “value2”). when(). get("/something");

This is useful when you want to reuse an entire specification across multiple requests.

The following settings are merged:

  • Parameters
  • Cookies
  • Headers