https://kotlinlang.org logo
#ktor
Title
# ktor
a

Aleksei Tirman [JB]

07/22/2022, 10:20 AM
What problem do you encounter? You can just combine resources and serialization.
l

Lidonis Calhau

07/22/2022, 10:27 AM
When I combine them I have a 404 Not Found for my route. That is why I wanted an example.
a

Aleksei Tirman [JB]

07/22/2022, 10:28 AM
Could you please share your code?
l

Lidonis Calhau

07/22/2022, 10:28 AM
I can share my project on github
a

Aleksei Tirman [JB]

07/22/2022, 10:28 AM
Ok
l

Lidonis Calhau

07/22/2022, 10:36 AM
a

Aleksei Tirman [JB]

07/22/2022, 12:41 PM
You need to rewrite your classes to that child resources have a reference to parent resources:
Copy code
@Serializable
@Resource("/bears/{name}")
class BearsResource(val name: String) {

    @Serializable
    @Resource("{id}")
    class Id(val parent: BearsResource, val id: String) {

        @Serializable
        @Resource("hibernate")
        class Hibernate(val parent: BearsResource.Id, val id: String)
    }
}
l

Lidonis Calhau

07/23/2022, 4:02 AM
Thanks for the help @Aleksei Tirman [JB] Is there a way to get the url from the the Id class, something like
Copy code
Id(BearsResource(),"123").toURL() -> "/bears/123"
I would need it to add the Location header when I create a bear
a

Aleksei Tirman [JB]

07/24/2022, 8:32 AM
Copy code
application.href(BearsResource.Id(BearsResource("name"),"123"))
l

Lidonis Calhau

07/24/2022, 2:05 PM
Thanks again. You have to get used to it, but I’m starting to like the new plugin.
23 Views