I have a simple Akka routes:
pathPrefix("api/games") {
parameters("id".as[String].optional, "name".as[String].optional, "type".as[String].optional ...) { (id, name, type) => {
get {...}
}
}
}
The problem is - I can have different number of optional parameters here. I do not want to pass all of them, because client can send different params. What is the best way to handle them dynamically (based on number of params) in akka-http?
I thought I can add all of them to list and check which are not None
:
val params = List(id, name, type ...)
But I think it is very naive.
parameterMap
may be helpful in your case. It extracts all parameters as Map[String, String]
. Or parameterMultiMap
if some parameter may repeat.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.