Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ktor: define route for URL with and without tailing slash

Tags:

kotlin

ktor

I am trying to learn Ktor, when responding to a GET request, I found that the trailing slash is treated as two routes, for example:

/greet?name=john
/greet/?name=john

Is it possible to define one route for the above two URLs, which is to handle trailing slash automatically?

like image 909
Nick Avatar asked Jul 15 '26 00:07

Nick


2 Answers

In your Application.module() or Application.configureRouting() add this:

install(IgnoreTrailingSlash)
like image 137
Hawt Sauce Avatar answered Jul 16 '26 13:07

Hawt Sauce


You can use the IgnoreTrailingSlash plugin to solve your problem.

like image 21
Aleksei Tirman Avatar answered Jul 16 '26 15:07

Aleksei Tirman