# Using feeder to build query string

**URL:** <https://community.gatling.io/t/using-feeder-to-build-query-string/2097>\
**Category:** Gatling (Open-Source)\
**Created:** [March 10, 2015, 11:30am UTC](https://community.gatling.io/t/using-feeder-to-build-query-string/2097 "2015-03-10T11:30:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xav.deschamp](https://avatars.discourse-cdn.com/v4/letter/x/e9bcb4/32.png) [@xav.deschamp](https://community.gatling.io/u/xav.deschamp)\
**Post date:** [March 10, 2015, 11:30am UTC](https://community.gatling.io/t/using-feeder-to-build-query-string/2097/1 "2015-03-10T11:30:34Z")

</div>

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](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

`

```auto
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=type,keyword)

[http://localhost?fields=keyword](http://localhost?fields=keyword)

[http://localhost?fields=theme,type](http://localhost?fields=theme,type)

[http://localhost](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](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.

`

---

<div class="post-metadata">

**Author:** ![jarrowwx](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@jarrowwx](https://community.gatling.io/u/jarrowwx)\
**Post date:** [March 10, 2015, 3:29pm UTC](https://community.gatling.io/t/using-feeder-to-build-query-string/2097/2 "2015-03-10T15:29:38Z")

</div>

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 \*/
