Passing a List in request body for POST call

1,178 views
Skip to first unread message

samir kumar Pradhan

unread,
Sep 23, 2015, 5:47:11 AM9/23/15
to Gatling User Group
I am trying to make a POST call:

I have a dynamically generated list of strings:

val resourceList = session("resourceNames").as[List[String]].mkString(",")

Now I need to pass this as request body:

.exec(http("Submit Resources List")
                     .post("/my-api-endpoint")
                     .body(StringBody("""["${resourcesForApp}"]""")).asJSON
                    .check(status.is(200))             
)

Basically the Rest body should look like:

["resource1", "resource2", "resource3"]

But my Java API is reading the request body as a single element in the list seperated by comma instead of reading 3 elements in the list as above.

How to correctly set the body in gatling request?








samir kumar Pradhan

unread,
Sep 23, 2015, 7:43:47 AM9/23/15
to Gatling User Group
*** resourcesForApp has been set in session for val resourceList.
session.set("resourcesForApp", resourceList)

John Arrowwood

unread,
Sep 24, 2015, 10:14:02 AM9/24/15
to Gatling User Group
At some point you will need to transform from a list to a string.  The default transformation doesn't quote the elements, which is what you are seeing.  So you will have to do a non-default transformation.  Instead of sending in an expression to StringBody, send in a session function, and have that function return the list converted to a JSON array.
Reply all
Reply to author
Forward
0 new messages