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

Cosmin Victor Celea

09/02/2020, 9:58 AM
Hei, I get the following error when trying to define a endpoint that starts with a dynamic path. (Example:
Path.of("system", "The target system ") / "/feed"
.
Exception in thread "main" java.lang.IllegalArgumentException: Fixed path segments cannot contain /. Use the "a / b" form.
Any ideas?
d

dave

09/02/2020, 9:59 AM
you don't need the prefixing /
c

Cosmin Victor Celea

09/02/2020, 10:00 AM
Path.of(“system”, “The target system “) / “feed”
?
d

dave

09/02/2020, 10:01 AM
yep
c

Cosmin Victor Celea

09/02/2020, 10:02 AM
still the same error
Copy code
return  Path.of("system", "The target system ") / "feed" meta {
d

dave

09/02/2020, 10:10 AM
Hmmm. Can you stick it in a gist please?
c

Cosmin Victor Celea

09/02/2020, 10:18 AM
I think i figure out where the problem is. In my code the static path is composed of 2 elements. Something like return Path.of(“system”, “The target system “) / “weather/feed” meta {
I think it does not like the “/” between weather and feed
Could this be it?
How would you define the endpoint in this case?
d

dave

09/02/2020, 10:23 AM
Aha - yes. You would use Path.of(“weather”) / “feed”
With suffix “strings” the bound handler function then takes 2 args- one of them is always “feed”.
Limitation of how it’s written I’m afraid
(And the type system)
c

Cosmin Victor Celea

09/02/2020, 10:25 AM
but if both weather and feed are static
then i still have to write
Path.of(“weather”) / “feed”
d

dave

09/02/2020, 10:25 AM
Aha - then “weather” / “feed”
c

Cosmin Victor Celea

09/02/2020, 10:25 AM
aha ok
thank you, will try
d

dave

09/02/2020, 10:26 AM
Or if that doesn’t work Path.fixed(“weather”) / “fixed “
(Haven’t got api in front of me)
c

Cosmin Victor Celea

09/02/2020, 10:26 AM
👍 will try both
thank you
d

dave

09/02/2020, 10:27 AM
👍
c

Cosmin Victor Celea

09/02/2020, 10:29 AM
Worked with Path.fixed but the in the HttpHandler i have to have all the paths as inputs
so for example getfeed(weatherPath: String): HttpHandler
d

dave

09/02/2020, 10:37 AM
Yep.
It’s because the path lens is basically matching on the input string.
Kotlin type system isn’t really powerful enough for what we’d ideally like.. 🙄
16 Views