Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kimar/ktor-middleware
A dead-simple Middleware Implementation for the Ktor Web Framework
https://github.com/kimar/ktor-middleware
backend kotlin ktor maven middleware webapp
Last synced: 9 days ago
JSON representation
A dead-simple Middleware Implementation for the Ktor Web Framework
- Host: GitHub
- URL: https://github.com/kimar/ktor-middleware
- Owner: kimar
- Created: 2017-10-03T10:10:11.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-01-19T10:44:55.000Z (almost 4 years ago)
- Last Synced: 2024-10-08T00:42:48.379Z (about 1 month ago)
- Topics: backend, kotlin, ktor, maven, middleware, webapp
- Language: Kotlin
- Homepage:
- Size: 32.2 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ktor-Middleware
## A dead-simple middleware for Kotlin/Ktor
### Installation
### pom.xml
```java
com.github.kimar
Ktor-Middleware
0.2.2```
### build.gradle
```java
compile 'com.github.kimar:Ktor-Middleware:0.2.2'
```### Usage
#### Inside your route handler
Let's assume you've got an `upload` route you'd like to secure using `BearerAuthentication`, one way would be to install this routing using `Ktor-Middleware` which will then, in turn, automatically filter all failed middlewares and report and error accordingly, e.g.:
```java
fun Application.module() {
...
install(Routing) {
upload(listOf(BearerAuthentication("secret_token"))
}
}fun Routing.upload(middlewares: List>): Route {
return post("upload") {val eval = middlewares.evaluate(this)
when(eval.success) {
true -> success(call)
else -> call.respondText(eval.result!!.gsonify(), ContentType.Application.Json)
}
}
}private fun success(call: ApplicationCall) {
...
}
```