Sunday, February 7, 2016

Gatling post request with JSON body

To make a POST request in Gatling with JSON request body use the following code -
import net.liftweb.json.DefaultFormats
import net.liftweb.json.Serialization._

object PersonScript {
  case class Person(name: String)

  val createPerson = http("Create person")
    .body(StringBody(session => write(Person("Jack"))(DefaultFormats))).asJSON

The Person case class represents the JSON body structure you want to post.
The StringBody code line converts the case object into JSON representation for post.
Ensure to have following dependency in your classpath.

No comments:

Post a Comment