I’m trying to write a slug for Locations and am struggling to figure out exactly how to do it.
@Location("/files")
class Files{
@Location("/view/{id}/{slug?}")
data class View(val files: Files, val id: String, val slug: String?)
}
The following should match(i have IgnoreTrailingSlash installed):
/view/fileId
/view/fileId/
/view/fileId/some-description
/view/fileId/some-description/
having additional segment match would be fine, but unimportant:
/view/fileId/some-description/test123
I don’t actually care about the slug value, just that optionally an additional path segment can be passed at the end.
@Location("/files")
class Files {
@Location("/view/{id}/{...}")
data class View(val files: Files, val id: String)
}
Exception in thread “main” io.ktor.locations.LocationRoutingException: Path parameters ‘’ are not bound to ‘class com.domain.plugins.Files$View’ properties
The same exception is also thrown for
@Location("/files")
class Files {
@Location("/view/{id}/{...}")
data class View(val files: Files, val id: String, val slug: String)
}
Thanks. I had tried Array<String> with no luck, but for some reason did not try List<String>.
The following works as expected. Path parameters beyond {id} are optional and captured in the list.
@Location("/files")
class Files {
@Location("/view/{id}/{slug...}")
data class View(val files: Files, val id: String, val slug: List<String>)
}