https://kotlinlang.org logo
#http4k
Title
# http4k
a

alieksie

12/18/2018, 1:56 PM
Hi http4k! Is it possible to have optional path segment? Like:
Copy code
"/bar/" / Path.string().of(name = "foo")
comes
Copy code
"/bar/" / Path.string().of(name = "foo").optional
So it would match both
/bar/foo
and
/bar/
r

reik.schatz

12/18/2018, 2:00 PM
you could create 2 routes or?
d

dave

12/18/2018, 2:01 PM
yeah - there isn't the concept of an optional path param - you can map the same handler to both routes though
a

alieksie

12/18/2018, 2:03 PM
thanks, i will go with 2 routes option then!
r

reik.schatz

12/18/2018, 2:03 PM
Copy code
fun execute() { execute(null) }
fun execute(name: String?)

"/match/" bindContract Method.GET to ::execute
"/match/" / Path.string().of(name = "foo") bindContract Method.GET to ::execute
something along these lines 🙂
a

alieksie

12/18/2018, 2:04 PM
Thank you @reik.schatz
3 Views