This article will show you how to store Gatling response body, in other terms use save and print the response body in your Gatling Script.
Define HTTP Protocol
That’s where we define our base url and other configuration like headers, etc. For this example, all we need to have is baseUrl. For this example, we need to set Content-Type header as text/xml.
object Protocols { val httpProtocol = http .baseUrl("http://www.dneonline.com/") .contentTypeHeader("text/xml; charset=utf-8").build }
Make GET Request to Endpoint
This step is very straight forward. All you need to do is to make a basic Get request.
def jsonPath = exec(http("Get All ID's") .get("/todos")
Save Response Body
To get the response body, you should use the check function and use bodyString.saveAs( “VARIABLE_NAME” ) convention to store the response body.
def jsonPath = exec(http("Get All ID's") .get("/todos") .check( bodyString.saveAs( "RESPONSE_DATA" ) )))
Print the Response on Console
Apply the same approach to print the response body in the console.
def jsonPath = exec(http("Get All ID's") .get("/todos") .check( bodyString.saveAs( "RESPONSE_DATA" ) ))) .exec( session => { println("Some Restful Service Response Body:") println(session("RESPONSE_DATA").as[String]) session })
Happy Performance Testing with Gatling!

Canberk Akduygu is a Test Lead working in the Netherlands
Hi, how do i get exec(http(“Get All ID’s”) call just one time during the tests?