Venkat
07/24/2023, 6:14 AMChris Lee
07/24/2023, 7:18 AMVenkat
07/24/2023, 7:20 AMChris Lee
07/24/2023, 7:45 AMVenkat
07/24/2023, 7:52 AM@Resource("/articles")
internal object Articles
@Resource("/article")
internal data class Article(val parent: Articles = Articles)
fun main() {
embeddedServer(CIO, port = 8080){
install(Resources)
routing {
get<Articles> {
call.respondText("articles list")
}
get<Article> {
call.respondText("article")
}
}
}.start(true)
}
now it's the same again, it gives 405 for /articles but 404 /articles/articleVenkat
07/24/2023, 7:53 AMChris Lee
07/24/2023, 7:56 AMVenkat
07/24/2023, 8:02 AM@Resource("/articles")
internal class Articles {
@Resource("/article")
internal data class Article(val parent: Articles = Articles())
}
fun main() {
embeddedServer(CIO, port = 8080){
install(Resources)
routing {
get<Articles> {
call.respondText("articles list")
}
get<Articles.Article> {
call.respondText("article")
}
}
}.start(true)
}
Venkat
07/24/2023, 8:03 AMVenkat
07/24/2023, 8:04 AMVenkat
07/24/2023, 8:27 PM@Resource("/articles")
class Articles {
@Resource("{id}")
class Id(val parent: Articles = Articles(), val id: Long)
}
fun main() {
embeddedServer(CIO, port = 8080){
install(Resources)
routing {
get<Articles> {
call.respondText("articles list")
}
get<Articles.Id> {
call.respondText("article123")
}
}
}.start(true)
}
But it doesn't work for the path with parameter, in the above code I get the correct 405 PUT:/artcles
but for PUT:/articles/12
I get the wrong 404 status again. @Chris Lee do you have any idea?Chris Lee
07/24/2023, 8:39 PM@Resource("/{id}")
- paths always start with a /Venkat
07/24/2023, 8:42 PM/
as mentioned in the doc https://ktor.io/docs/type-safe-routing.html#resource_path_paramChris Lee
07/24/2023, 8:44 PMget
- you’ve stated using PUT
. Try just with GET
requests firts.Venkat
07/24/2023, 8:47 PMGET
works without any issue (either with or without /
). My problem is the wrong status code for the method is not defined for the path. I'm expecting 405 Method not allowed but ktor gives 404 Not foundChris Lee
07/24/2023, 8:48 PMVenkat
07/24/2023, 8:48 PM/articles/{id}/article
Venkat
07/24/2023, 8:50 PMis it documented to return a 405? that's often framework-specific and a bit subjective; there is not a handler that accepts PUT at that URL.
it's the standard response https://github.com/ktorio/ktor/issues/649 ktor already has this issue but it's closed for some reasonChris Lee
07/24/2023, 8:51 PMVenkat
07/24/2023, 8:54 PMChris Lee
07/24/2023, 8:54 PM