Ktor: handle in Route not executing lambda

Created on 27 Aug 2019  路  4Comments  路  Source: ktorio/ktor

Ktor Version and Engine Used (client or server and name)
Ktor v1.2.3, TestApplicationEngine

Describe the bug
I am building a Feature for rest repositories, when registering the routes for a specified HttpMethod, the lambda passed to the handle method is never executed. Here my repo's issue

To Reproduce
Here's the code to reproduce it. Strangely the response is null, check out the test results on TravisCI here .

bug

All 4 comments

May be related to this.

The first bug I've noticed is in Utils.kt lines 49 and 61: entityIdTag should be placed inside of {}, otherwise it leads to a constant path requirement, for example, repositories/intidentities/entityIdTag that is never requested, should be
repositories/intidentities/{entityIdTag}.

After fixing this, integer entities test still no luck: the second request is PUT, but your repository is creating POST routes instead.

Also, when sending a request body, one should also provide Content-Type request header. Otherwise, a server may respond with 415 Unsupported Media Type.

Also, you can use routing resolution trace for debugging complex routing trees:

    routing {
        trace { trace ->
            println(trace.buildText())
        }
    }

See https://ktor.io/servers/features/routing.html#tracing

Thank you very much! Using the trace function (which I was not aware at all) I discovered that the problems were indeed the Content-Type for multiple items and the forgotten parenthesis for both single and multiple items!

Was this page helpful?
0 / 5 - 0 ratings