How to create base HTTP request with common query parameters

502 views
Skip to first unread message

mike.pet...@gmail.com

unread,
May 11, 2021, 9:42:39 AM5/11/21
to Gatling User Group
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!

Stéphane LANDELLE

unread,
May 11, 2021, 10:59:11 AM5/11/21
to gat...@googlegroups.com
> 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?




Logo Stéphane Landelle
Chief Technical Officer
twitter: @slandelle
site:
gatling.io




--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gatling/87c9dad1-1c82-4e03-b370-35d65c77df32n%40googlegroups.com.

mike.pet...@gmail.com

unread,
May 11, 2021, 11:18:49 AM5/11/21
to Gatling User Group
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))
)


Sri Harsha G

unread,
May 11, 2021, 3:02:35 PM5/11/21
to Gatling User Group
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 <Simulation Name> extends Simulation  with HttpSupport  {
 val httpConf = getHttpConf

httpConf.queryParam()
......
......
......

mike.pet...@gmail.com

unread,
May 11, 2021, 4:32:13 PM5/11/21
to Gatling User Group
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?

Sri Harsha G

unread,
May 11, 2021, 5:13:41 PM5/11/21
to Gatling User Group
You can try adding that to the trait method getHttpConf... and pass the query param values are parameters to the method

Stéphane LANDELLE

unread,
May 12, 2021, 10:57:54 AM5/12/21
to gat...@googlegroups.com
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"))

Logo Stéphane Landelle
Chief Technical Officer
twitter: @slandelle
site:
gatling.io



mike.pet...@gmail.com

unread,
May 12, 2021, 12:15:59 PM5/12/21
to Gatling User Group
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

On Tuesday, May 11, 2021 at 3:02:35 PM UTC-4 srihars...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages