Reputation: 31
I am trying to make a PUT call via Gatling and trying to pass a List as a request body:
.put("/mypath").body(List(session("usernames")).asJSON.check(status.is(200))
Where I have usernames in a session and it is a List of strings.
Body should become: ["string1", "string2"....]
Any solution on how to pass List as a request body. I am new to Gatling. Please help.
Upvotes: 2
Views: 1822
Reputation: 1778
Try this:
.put("/mypath")
.body(StringBody("${usernames.jsonStringify()}").asJSON)
.check(status.is(200))
jsonStringify is part of the Expression Language (EL) and turns your list into a JSON string. The .asJSON at the end ensures the Content-Type is set correctly to application/json.
Upvotes: 0