testing REST services in gatling with example

Hi Everyone,

can anyone suggest me on how to test REST services in gatling with example?

i know how to record and execute recorded script,but i don’t know how to test REST services using these things.

Have you had a look at the example tests that are included in the Gatling download?

Simply use these as a starting point and alter the urls and parameters to match what you’re trying to test.

You have a GET to test?

.exec(http(“GET web service”)
.get(“http://yoururl.com/service/fortesting”)
.queryParam(“paramA”, “X”)
.queryParam(“paramB”, “5”)

Easy. How about a POST with some JSON data?

.exec(http(“A POST test”)
.post(“http://yoururl.com/service/fortesting”)
.body(StringBody("""
{ “hereIsAField” : “thatWasAField”,
“date” : “2014-09-15T14:22:00” ,
“ids” : [“123”, “321”],
“”")).asJSON

Just as easy. Once these are in place, you can play with different load behaviours (e.g. one call every minute, 20 concurrent calls over and over again as quickly as possible…).

Just experiment with the DSL (look at the cheat sheet for your version of Gatling here: http://gatling.io/docs/ ) and have some fun.

Jason

i am not able to send JSON string as a parameter,

my case is like bellow…

val userjsonbody="""[{"``query``": "``%``s``", "``params``": {"``ids``": %s}}]"""

val scn = scenario(“scenario”).exec(http(“GET web service”)
.get(“http://yoururl.com/service/fortesting”)
.queryParam(“paramX”, “a”)
.queryParam(“paramY”, “b”)
.queryParam(“paramZ”, “c”)
.queryParam(“jsonVO”, “userjsonbody”))

setUp(scn.inject(atOnce(1 user))).protocols(httpProtocol)

but i am unable to get the response by using above code

if i am trying to post the JSON string like this i got an error

val scn1 = scenario(“scenario”).exec(http(“GET web service”)
.get(“http://yoururl.com/service/fortesting”)
.queryParam(“paramX”, “a”)
.queryParam(“paramY”, “b”)
.queryParam(“paramZ”, “c”))

val scn2 = scenario(“scenario”).exec(http(“A POST test”)
.post(“http://yoururl.com/service/fortesting”)
.body(userjsonbody).asJSON)
val scn=scenario(“scenario”).exec(scn1,scn2)

setUp(scn.inject(atOnce(1 user))).protocols(httpProtocol)

my moto is to send request and getting the response

three params are strings and another one is JSON string as request

in my case response is as JSON array only…

here is my case

val userjsonbody="""[{“levelName”:“gdfbdfnfgmhg”,“operator”:“dfcnfcn”,“value”:“dfgnd”},
{“levelName”:“dsgdfhfhf”,“operator”:“EQUALS”,“value”:“fjnfgdgsgsdg”}]""".toString()

val scn = scenario(“scenario”).exec(http(“GET web service”)
.post(""“http://yoururl.com/service/fortesting”"")
.param(""“paramX”"", “”“value1"”")
.param(""“paramY”"", “”“value2"”")
.param(""“paramZ”"", “”“value3"”")
.body(userjsonbody)
.asJSON

what i need to do ? can anyone please suggest me on this…any suggetions are greatly appreciated.