DebugRoutes
The routes of a tab, as DebugTab.routes declares them. From the declarations, the tab's default DebugTab.handle routes each request, answers 405 for a declared path with another method and 400 with field for a missing or wrong parameter, and calls the route's handler. The tab's default DebugTab.schema returns an OpenAPI document made from the same declarations, so GET /api/v1/_meta lists the tab and the server can name the query parameters that a route does not declare.
@OptIn(ExperimentalDebugRoutes::class)
override fun routes(routes: DebugRoutes) {
routes.version = "1.0"
routes.get("snapshot") {
summary = "Poll the flags with an opaque cursor."
val cursor = query.string("cursor") { description = "The cursor of the previous response." }
handle { call -> snapshot(call[cursor]) }
}
}A route's path is relative to /api/v1/<tab id>/, such as snapshot or items/{id}: a segment in braces is a path parameter, which the route declares with DebugRoute.path. A literal segment wins over a parameter, so items/new and items/{id} can both exist. For the route's own method, a segment that its parameter does not take, such as items/x for an int {id}, matches no route, so the client gets 404. The router checks the method before the path parameters, so another method gets 405 with an Allow header: with only DELETE items/{id}, GET items/x gets Allow: DELETE. The path "" declares the route at the tab root, /api/v1/<tab id>, such as the list and the create of a collection. The router ignores one slash at the end of a request's path, so seed/ reaches the route seed.
A mistake in the declarations, such as two routes with the same method and path, a path parameter that the route does not declare, a JSON fragment that is not valid JSON, or a route without DebugRoute.handle, throws IllegalStateException from the first DebugTab.handle or DebugTab.schema call. A unit test that calls tab.schema() finds it.
The API is for Kotlin. Java is not a target: the declaration blocks are Kotlin function types with a receiver.