Search code examples
scalaperformance-testinggatlingscala-gatling

Send Authorization Token | Gatling


I am performance testing our Enterprise API using Gatling. While testing with "Postman" I used to pass following Headers:

  • API Key
  • Authorization Bearer Token

It would be great if someone could help me: How can I pass "API-KEY" and "Authorization Bearer" token as a header in a Gatling request?

Please see my code below:

val headers_10 = Map("Content-Type" -> """application/json""")

    val httpConf = http
        .baseURL(perfProdURL)
        .acceptHeader("application/json, */*")
        .acceptCharsetHeader("UTF-8")

    val scn = scenario("Vertex API Test01")
        .exec(
            http("request_1")
            .post("/details/orders")
            .headers(headers_10)
            .check(status.is(200))
            .body(RawFileBody("/Users/z063011/Sunil/test.json")).asJSON)

Solution

  • As mentioned in the comments, you can add additional fields to your already defined headers map like this:

    val headers_10 = Map("Content-Type" -> """application/json""", "API-KEY" -> "your_api_key", "Authorization Bearer" -> "auth_bearer")
    

    You might also want to check out the docs on headers.