Hey everyone, I’d like to confirm something on how...
# ktor
p
Hey everyone, I’d like to confirm something on how tailcards work in routing. The examples in the docs: https://ktor.io/docs/server-routing.html#match_url show that the tailcard
{…}
always follows a
/
(end of a path segment). Is this a requirement or can the tailcard be used anywhere in the path? For example, a route like
/test{…}
. I’ve tested this and it works precisely as I want; I just like to confirm that this is also intended and will not be patched later.
a
The tail card can be used anywhere in the path and will match the rest of the URL path.
gratitude thank you 1
p
There seems to be some difference that I would like to point out. Example A:
Copy code
routing {
    get(“/{…}”) {
        call.respond(“root”)
    }

    get(“/test/{…}”) {
        call.respond(“test”)
    }
}
Example B:
Copy code
routing {
    get(“/{…}”) {
        call.respond(“root”)
    }

    get(“/test{…}”) {
        call.respond(“test”)
    }
}
Now if I use on Example A:
client.get(“/test/someextra”)
I get response:
“test”
. If I use on Example B:
client.get(“/test/someextra”)
I get response:
“root”
. If I switch the order of routes in example B I then get response:
“test”
. Do I understand correctly that the order of routes matter in the case you try to match with tail cards on the same path segment?
a
Strangely, the request for Example B results in a 404. So, it seems to matter that the tail card starts in a separate path segment.
p
I don’t get a 404 🤔 when I’m at my pc I can create a project to share to show you exactly what I test.