# Custom feeder that fetches data from an API

**URL:** <https://community.gatling.io/t/custom-feeder-that-fetches-data-from-an-api/6171>\
**Category:** Gatling (Open-Source)\
**Created:** [June 30, 2021, 1:16pm UTC](https://community.gatling.io/t/custom-feeder-that-fetches-data-from-an-api/6171 "2021-06-30T13:16:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SuperJuBoy](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@SuperJuBoy](https://community.gatling.io/u/SuperJuBoy)\
**Post date:** [June 30, 2021, 1:16pm UTC](https://community.gatling.io/t/custom-feeder-that-fetches-data-from-an-api/6171/1 "2021-06-30T13:16:58Z")

</div>

Hey,

I have a requirement where I need to fetch a password from an API and use it as payload in an authentication request.

I’m using a custom feeder for the purpose. Something like this

val passwordFeeder= Iterator.continually(Map(“password” → getPassword()))

and then

feed(passwordFeeder)

However as I understand every call to the “feed” method will make a call to the , I want to avoid this since its a system outside the test scope, which shouldn’t be receiving this extra traffic.

How can I modify the behavior to feed once and use the data repeatedly.

regards,  
Aju

---

<div class="post-metadata">

**Author:** ![sbrevet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/sbrevet/32/830_2.png) [@sbrevet](https://community.gatling.io/u/sbrevet)\
**Post date:** [June 30, 2021, 1:52pm UTC](https://community.gatling.io/t/custom-feeder-that-fetches-data-from-an-api/6171/2 "2021-06-30T13:52:43Z")

</div>

Hey,

`Iterator.continually` takes a “[called by name](https://www.baeldung.com/scala/parameters-by-value-by-name)“ parameter.  
If I understood correctly, you want to call getPassword once.  
You can do so by having your password value retrieved before creating your feeder.

```auto
val password = getPassword(<API URL>)
val passwordFeeder = Iterator.continually(Map("password" -> password))

// ...

feed(passwordFeeder)

```

Cheers!

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [June 30, 2021, 2:18pm UTC](https://community.gatling.io/t/custom-feeder-that-fetches-data-from-an-api/6171/3 "2021-06-30T14:18:28Z")

</div>

Then, you have to understand that feeders are meant to be able to immediately return data, typically from memory, or worst case scenario from local fast disk.  
If you’re performing a blocking network call every time your feeder is trying to fetch a record, you’re going to kill performance. If that’s what you’re trying to achieve, you should use a silent Gatling request instead.

---

<div class="post-metadata">

**Author:** ![SuperJuBoy](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@SuperJuBoy](https://community.gatling.io/u/SuperJuBoy)\
**Post date:** [June 30, 2021, 2:30pm UTC](https://community.gatling.io/t/custom-feeder-that-fetches-data-from-an-api/6171/4 "2021-06-30T14:30:06Z")

</div>

Thanks Sebastian, it seems fairly obvious looking at it now 🙂

@Stephane - Sebastian’s suggestion would work just fine, the getPassword function is called once and the value is stored in a variable (in memory) and the value is retrieved from memory there on, without making expensive calls over the network for each record fetch.
