The following passes (taken from https://gatling.io/docs/2.3/http/http_request/, removed .toJSON
as it did not exist), but does not add an entry to the REST API:
class TestREST extends Simulation {
val httpProtocol = http
.baseUrl("http://127.0.0.1:5000") // Here is the root for all relative URLs
val scn = scenario("UploadMany") // A scenario is a chain of requests and pauses
.exec(http("request_1")
.put("/")
.body(StringBody("""{
"text":"lalala", "title": "hello world", "date": "12346"}"""))
.check(status.is(200))
)
setUp(scn.inject(atOnceUsers(1)).protocols(httpProtocol))
}
How do you add JSON data to a .put
request with Gatling?
I had removed the .asJSON
from the example at https://docs.gatling.io/reference/script/protocols/http/request/#asxxx, as it failed. This method was renamed to (capitalized) .asJson
in 3.1, so the following change fixes it:
.body(StringBody("""{
"text":"lalala", "title": "hello world", "date": "12346"}""")).asJson