Created
May 18, 2021 06:29
-
-
Save darkxanter/d40b994eec691d69dd931cc9e60bb935 to your computer and use it in GitHub Desktop.
ktor rate limit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Application.module(testing: Boolean = false) { | |
val config = RateLimiterConfig.custom() | |
.limitRefreshPeriod(Duration.ofMillis(1)) | |
.limitForPeriod(10) | |
.timeoutDuration(Duration.ofMillis(25)) | |
.build() | |
val rateLimiterRegistry = RateLimiterRegistry.of(config) | |
val testRateLimiter = rateLimiterRegistry | |
.rateLimiter("test") | |
routing { | |
get("/") { | |
testRateLimiter.executeSuspendFunction { | |
call.respondText("HELLO WORLD!", contentType = ContentType.Text.Plain) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment