Using feeder to build query string

Hello!

I am new to Gatling / Scala and I have some problems that can be linked to the following post, but since it seems outdated now (I am using Gatling 2.1.4),I could not find an easy (and standard) way to resolve it with this thread.

https://groups.google.com/forum/#!msg/gatling/Cxj6jUhrjaE/YREefcnoEroJ

I want to load test a REST API and for that I take different feed that I will add to the “get” or “post” URL.

my SSV (buffet_fields) looks like that

`

number;fields
1;type
2;keyword
3;theme

`

For each of these SSV, I want to take a random number of items to add in the URL:

e.g.
http://localhost?fields=type,keyword

http://localhost?fields=keyword

http://localhost?fields=theme,type

http://localhost

For the moment my solution take a random number to know how many items will be taken in the URL (0-1-2-3), then, at each iteration, add a random field into the “retrunedString” which will be later added in the URL.There can be duplicated fields (http://localhost?fields=keyword,keyword). I can obviously add a parameter to avoid that but I am pretty sure that a more simple / aesthetic solution exists, even in term of performance.

`

Don’t try to do it all in scala, unless you are prepared to dive into the internals of the feeder. Instead, use the Gatling DSL. Use a repeat() loop

.exec( session => session.set( ‘keywords’, /* empty list, set, array, string, whatever is easiest / ) )
.repeat( session => /
random number between 1 and … / ) {
feed( /
source / )
.exec( session => session.set( ‘keywords’, /
expression to add another value to the list / )
}
/
session.keywords now contains a list, just convert it to a string and you are good to go */