Akka http parameter optional dsl error

I have a route like /test?format=xx
and parameter format is optional

in scala, I wrote:

path("test") {
    parameters("format".optional) {format =>
      get {
        complete(...)
      }
    }

But I got the following error:
value optional is not a member of String
parameters(“format”.optional) {format =>

I already imported
import akka.http.scaladsl.server.{Directive0, Directives}

and
import Directives._

what am I missing?

Thanks.

Hi @rhibiscusc,

which version of akka-http do you use? optional has only be introduced recently, I think, in 10.2.0.

Can you check if "format".? would work?

Johannes

you are right. The version I use is way too old. Thank you!

@jrudolph How should I specify optional parameter with old version 2.4.11? I can’t quite find documentation for this old version. Thanks

I find this documentation: https://doc.akka.io/docs/akka-http/current/routing-dsl/directives/parameter-directives/parameter.html

it seems it does not support optional parameter with 2.4.11.

is there a workaround?

never mind. find it and use .?

Thanks @jrudolph