# API level testing

**URL:** <https://community.gatling.io/t/api-level-testing/1875>\
**Category:** Gatling (Open-Source)\
**Created:** [January 8, 2015, 9:58pm UTC](https://community.gatling.io/t/api-level-testing/1875 "2015-01-08T21:58:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zique\_Sousa](https://avatars.discourse-cdn.com/v4/letter/z/6f9a4e/32.png) [@Zique\_Sousa](https://community.gatling.io/u/Zique_Sousa)\
**Post date:** [January 8, 2015, 9:58pm UTC](https://community.gatling.io/t/api-level-testing/1875/1 "2015-01-08T21:58:47Z")

</div>

I need some help putting together a Gatling to test stress my API. I am still new to Gatliong so any help would be appreciated.

so I have this new service API called “getDriver” using the “Advanced rest client” on chrome I pass in header and a body and it returns result.

example:  
POST  
[https://Myserver-service](https://Myserver-service)…mycompany.com/uservice/http/driver/json

Header is context: {“uID”:0,“gId”:0,“drId”:159577,“cId”:0,"\_\_isset\_bitfield":4,“optionals”:[“CLIENT”]}

Body is [1,“getDriver”,1,1,{“1”:{“rec”:{“1”:{“i64”:0},“4”:{“i64”:12345},“5”:{“i64”:0}}}}]

My question is how do I take this and convert it to a Gatling test ?

this is what I have so far, which I know is not correct!!!

import scala.concurrent.duration.\_

import io.gatling.core.Predef.\_  
import io.gatling.http.Predef.\_  
import io.gatling.jdbc.Predef.\_

class Test extends Simulation {

val httpProtocol = http  
.baseURL(“[https://myserver-uservice.mycompany.com](https://myserver-uservice.mycompany.com)”)  
.inferHtmlResources()  
.acceptHeader("""_/_""")  
.acceptEncodingHeader(""“gzip, deflate”"")  
.acceptLanguageHeader(""“en-US,en;q=0.5"”")  
.connection(""“keep-alive”"")  
.contentTypeHeader(""“application/x-www-form-urlencoded; charset=UTF-8"”")  
.userAgentHeader(""“Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0"”")

val headers\_0 = Map(  
//""“context”""-\> “”"{“uId”:0,“gId”:0,“dId”:159577,“cId”:0,"\_\_isset\_bitfield":4,“optionals”:[“CLIENT”]}""",  
“”“Content-Type”"" → “”“text/json; charset=UTF-8"”"  
)

val scn = scenario(“addonestop”)  
.exec(http(“API”)  
.post("""/userservice/http/driver/json""")  
.headers(headers\_0)  
.body(StringBody(""""[1,“getDriver”,1,1,{“1"”: “{“rec”:{“1”:{“i64”:0},“4”:{“i64”:159577},“5”:{“i64”:0}}}}]” }""")).asJSON  
)  
.pause(4)

setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)  
}

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [January 9, 2015, 8:19am UTC](https://community.gatling.io/t/api-level-testing/1875/2 "2015-01-09T08:19:41Z")

</div>

What’s the problem exactly?

---

<div class="post-metadata">

**Author:** ![Zique\_Sousa](https://avatars.discourse-cdn.com/v4/letter/z/6f9a4e/32.png) [@Zique\_Sousa](https://community.gatling.io/u/Zique_Sousa)\
**Post date:** [January 9, 2015, 1:22pm UTC](https://community.gatling.io/t/api-level-testing/1875/3 "2015-01-09T13:22:21Z")

</div>

The problem is I don’t know to create a Gatling test that will test my API. Given the information below, I am not sure how to translate taht into a Gatling script.

POST  
[https://Myserver-service…mycompany.com/uservice/http/driver/json](https://Myserver-service..mycompany.com/uservice/http/driver/json)

Header is context: {“uID”:0,“gId”:0,“drId”:  
159577,“cId”:0,"\_\_isset\_bitfield":4,“optionals”:[“CLIENT”]}

Body is [1,“getDriver”,1,1,{“1”:{“rec”:{“1”:{“i64”:0},“4”:{“i64”:12345},“5”:{“i64”:0}}}}]

---

<div class="post-metadata">

**Author:** ![Abhinav\_Gogna](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Abhinav\_Gogna](https://community.gatling.io/u/Abhinav_Gogna)\
**Post date:** [January 9, 2015, 4:42pm UTC](https://community.gatling.io/t/api-level-testing/1875/4 "2015-01-09T16:42:53Z")

</div>

It sounds like you are trying to stress/load test json response. You probably want to parametrize the script and want to stress with multiple users.

Gatling will be able to handle the tasks. Why not start with the tutorial? [http://gatling.io/docs/2.1.2/quickstart.html](http://gatling.io/docs/2.1.2/quickstart.html) and [http://gatling.io/docs/2.1.2/advanced\_tutorial.html](http://gatling.io/docs/2.1.2/advanced_tutorial.html)

It covers the basic and you will be able to simple scripts in no time.

---

<div class="post-metadata">

**Author:** ![Zique\_Sousa](https://avatars.discourse-cdn.com/v4/letter/z/6f9a4e/32.png) [@Zique\_Sousa](https://community.gatling.io/u/Zique_Sousa)\
**Post date:** [January 9, 2015, 4:55pm UTC](https://community.gatling.io/t/api-level-testing/1875/5 "2015-01-09T16:55:57Z")

</div>

no, all I want is an example of how to test a REST API

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [January 9, 2015, 6:11pm UTC](https://community.gatling.io/t/api-level-testing/1875/6 "2015-01-09T18:11:03Z")

</div>

[http://ivanursul.com/2015/01/testing-restful-web-service-gatling-integration-tool/](http://ivanursul.com/2015/01/testing-restful-web-service-gatling-integration-tool/)

---

<div class="post-metadata">

**Author:** ![Zique\_Sousa](https://avatars.discourse-cdn.com/v4/letter/z/6f9a4e/32.png) [@Zique\_Sousa](https://community.gatling.io/u/Zique_Sousa)\
**Post date:** [January 9, 2015, 7:16pm UTC](https://community.gatling.io/t/api-level-testing/1875/7 "2015-01-09T19:16:19Z")

</div>

I keep on geting a 406 error

package addonestop

import scala.concurrent.duration.\_

import io.gatling.core.Predef.\_  
import io.gatling.http.Predef.\_  
import io.gatling.jdbc.Predef.\_

class addonestop extends Simulation {

val httpProtocol = http  
.baseURL(“[http://myserver-uservice.mycompany.com](http://myserver-uservice.mycompany.com)”)

.inferHtmlResources()  
.acceptHeader(“text/html,application/xhtml+xml,application/xml;q=0.9,_/_;q=0.8”)  
.doNotTrackHeader(“1”)  
.acceptEncodingHeader(""“gzip, deflate”"")  
.acceptLanguageHeader(""“en-US,en;q=0.5"”")  
.connection(""“keep-alive”"")  
.contentTypeHeader(""“application/x-www-form-urlencoded; charset=UTF-8"”")  
.userAgentHeader(""“Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0"”")

val headers\_0 = Map(  
“”“Accept”"" → “”“application/json, text/javascript, _/_; q=0.01"”",  
“”“Cache-Control”"" → “”“no-cache”"",  
“”“Content-Type”"" → “”“application/json; charset=UTF-8"”",  
“”“Pragma”"" → “”“no-cache”"",  
“”“X-Requested-With”"" → “”“XMLHttpRequest”"")

val scn = scenario(“addonestop”)  
.exec(http(“API”)  
.post("""/userservice/http/driver/json""")  
.headers(headers\_0)  
.body(StringBody(""“context:{“userId”:0,“groupId”:0,“driverId”:12345,“companyId”:0,”\_\_isset\_bitfield":4,“optionals”:[“CLIENT”]}""")).asJSON  
)

setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)  
}

---

<div class="post-metadata">

**Author:** ![Zique\_Sousa](https://avatars.discourse-cdn.com/v4/letter/z/6f9a4e/32.png) [@Zique\_Sousa](https://community.gatling.io/u/Zique_Sousa)\
**Post date:** [January 9, 2015, 7:39pm UTC](https://community.gatling.io/t/api-level-testing/1875/8 "2015-01-09T19:39:46Z")

</div>

so let me try to explain what I am trying to achieve… I am usikng this tool from googl ecalled “Advanced Rest  
Client”, to test my API with this tool I supply a raw format header (context:{“uId”:0,“gId”:0,“dId”:12345,“companyId”:0,"\_\_isset\_bitfield":4,“optionals”:[“CLIENT”]}) and a body

[1,“getDriver”,1,1,{“1”:{“rec”:{“1”:{“i64”:0},“4”:{“i64”:12345},“5”:{“i64”:0}}}}].

so now I want to do the same test in gatling, but I am bnot sure how to build the gatling script.
