WebMiddleware

fun interface WebMiddleware

Defines a WebMiddleware interface used for handling HTTP requests in a Ktor application. Middleware allows modifying the request/response pipeline or adding custom behavior for specific routes.

Example:

val loggingMiddleware = object : WebMiddleware {
override suspend fun handle(call: ApplicationCall, next: suspend () -> Unit) {
// Custom logic here
next() // Call the next middleware or request handler
}
}

Inheritors

Properties

Link copied to clipboard
open val name: String?

The name of the middleware. This is an optional property. It can be used for logging, debugging, or middleware identification.

Functions

Link copied to clipboard
abstract suspend fun handle(call: ApplicationCall, next: suspend () -> Unit)

The function to handle the HTTP request. It can modify the request, perform actions, or pass control to the next middleware/handler in the pipeline.