DebugRoute

One route of a tab: its documentation, its parameters, its body, its response, and the handler that answers it. DebugRoutes.get and the other methods of DebugRoutes declare it.

Each parameter that the block declares returns a DebugParam, and the handler reads its value from the DebugCall with it: call[cursor]. The block runs once, when the tab declares its routes; the handler runs for each request.

Properties

Link copied to clipboard

Whether the route also takes its body fields as an application/x-www-form-urlencoded form, as curl -d id=dark-mode sends it. Off by default: the route then reads every body as JSON, whatever its content type. A route with a DebugBodyParams.json field can't take a form.

Link copied to clipboard

The fields of the route's request body, a JSON object, or a form when acceptsForm is on. When the route declares a required field, an empty body gets a 400 with field body.

Link copied to clipboard

A description of the request body, for the OpenAPI document.

Link copied to clipboard

A longer description of the route, for the OpenAPI document.

Link copied to clipboard

The OpenAPI operationId. Without it, one made from the method and the path, such as getSnapshot, or getRoot for the route at the tab root.

Link copied to clipboard

The parameters in the route's path: one for each segment in braces.

Link copied to clipboard

The query parameters of the route.

Link copied to clipboard

A short summary of what the route does, for the OpenAPI document.

Functions

Link copied to clipboard
fun errors(vararg statuses: Int)

Adds error statuses that the route's handler can answer, such as 404, to the OpenAPI document. The document already lists the statuses that the server can answer for any route, 400 for a route with a body or a query parameter that the router can refuse, and 404 for a path parameter that does not take every segment.

Link copied to clipboard
fun handle(handler: DebugHandler)

Sets the handler that answers the route. It runs for each request whose parameters are valid, off the main thread and possibly at the same time as other requests, as DebugTab.handle does.

Link copied to clipboard
fun rawBody(contentType: String, schema: String)

Says that the route reads its whole body itself, as contentType (such as application/json) that the JSON Schema schema describes. The route then gets a 400 with field body for an empty body, and the handler reads DebugRequest.body. A route can't have both a raw body and body fields.

Link copied to clipboard
fun response(description: String, schema: String? = null, declare: DebugResponseSpec.() -> Unit = {})

Describes the route's success response for the OpenAPI document: its description, and the JSON Schema schema of its application/json body, or none. declare adds a body of another content type, such as the bytes of DebugResponse.bytes, and the response's headers: