简体   繁体   中英

Change some Path Parameters of an Akka Http service to Query Params

I have the following code that takes path parameters;

def candlesRange: Route = (path("candles" / Segment / Segment / IntNumber / LongNumber / LongNumber) & get) {
  (a1, a2, tf, t1, t2) => complete(apiController.apiGetCandlesRange(a1, a2, tf, t1, t2))
}

But I want to change some of the parameters to be Query Parms. So the URL will follow a format like this;

/candles/Asset1/Asset2/timeStart=1507198441000&timeEnd=1512382501000&interval=60m

And pass them through to the same method (Perhaps even removing the 'm' from the minutes as the param on the method is an int)

How can change this route to do this in Scala Akka Http. The only examples I can find use Path params

Read about parameters here: https://doc.akka.io/docs/akka-http/current/routing-dsl/directives/parameter-directives/parameters.html

val candlesRange: Route = (path("candles" / Segment / Segment / )) { (a1, a2) =>
    get {
        parameters('timeStart, 'timeEnd, 'interval) { (timeStart, timeEnd, interval) => 
            complete(apiController.apiGetCandlesRange(a1, a2, timeStart, timeEnd, interval))
    }
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM