Just to followup, in case anyone may be having the same challenge.
The way that I have solved it, at the moment is by having a package.object that I use in my models/ package, and then overriding HTTP methods in a helper object.
package object models {
implicit def apiHttp(requestName: Expression[String]):HttpHelper = new HttpHelper(requestName)
}
My HttpHelper object is looking like
class HttpHelper(requestName: Expression[String]) extends Http(requestName: Expression[String]) {
private final val SESSION_TOKEN = "X-Session-Token"
override def get(url: Expression[String]) = httpRequest("GET", url).header(SESSION_TOKEN, "${session_token}")
override def get(uri: Uri) = httpRequest("GET", Right(uri)).header(SESSION_TOKEN, "${session_token}")
override def put(url: Expression[String]) = httpRequest("PUT", url).header(SESSION_TOKEN, "${session_token}")
override def post(url: Expression[String]) = httpRequest("POST", url).header(SESSION_TOKEN, "${session_token}")
override def patch(url: Expression[String]) = httpRequest("PATCH", url).header(SESSION_TOKEN, "${session_token}")
override def head(url: Expression[String]) = httpRequest("HEAD", url).header(SESSION_TOKEN, "${session_token}")
override def delete(url: Expression[String]) = httpRequest("DELETE", url).header(SESSION_TOKEN, "${session_token}")
override def options(url: Expression[String]) = httpRequest("OPTIONS", url).header(SESSION_TOKEN, "${session_token}")
}
For all requests, but the initial one I then use ‘apiHttp’ instead of ‘http’, example:
val items = {
exec(apiHttp("history-items")
.get("/v1/history/items)
)
}
My initial request, that is to take place at least once during a virtual user session saves the session_token into the session.
exec(http("sessions-get")
.post("/v1/sessions")
.body(StringBody(Json.stringify(jsonBody)))
.check(
status.is(201),
jsonPath("$.session_token").saveAs("session_token")
)
)