I'm new to Finatra and scala. I need to store the ip address with another data in a post request. I'm using a custom case class:
case class MyRequest(name : String, email: String)
How can I also get remoteAddress in this request?
Thanks in advance.
Asked
Active
Viewed 440 times
2 Answers
2
I just find it in the document, you can implement your case class looks like this:
case class MyRequest (
request: Request,
name : String,
email: String
)
and the request
is the type of com.twitter.finagle.http.Request
, so you can access remoteAddress in this way:
post("/[your-api]") { r: MyRequest
val ip = r.request.remoteAddress
}

kemiya
- 460
- 2
- 5
- 16
0
It seems you can't. If your request type is a custom case class. Probably you can do something like the following, and use jackson for deserialisation the request to your own case class:
post("/{your-api-path}/") {
r: Request =>
val remoteIP = r.remoteHost
val myRequest = objectMapper.readValue(r.contentString, classOf[MyRequest])
...
}

Jiji TANG
- 91
- 3