Skip to content

KAMO030/ktor-spring-boot-starter

Repository files navigation

ktor-spring-boot-starter

使用

  • application.yml

    ktor:
      server:
        path: "/kamo"
        port: 8008
        host: "127.0.0.1"
  • routing

    1. KtorRouter
     @Controller
     // or @Component
     class TestController : KtorRouter {
         override fun Routing.register() {
             get("/a") { a() }
             get("/b") { b() }
         }
    
         suspend fun PipelineContext<Unit, ApplicationCall>.a() {
             call.respondText { "a" }
         }
    
         suspend fun PipelineContext<Unit, ApplicationCall>.b() {
             call.respondText { "b" }
         }
     }
    1. KtorRouterFun (KtorRouterFun = Routing.() -> Unit)
     @Component
     class TestRouting {
         @Bean
         fun c(): KtorRouterFun = {
             get("/c") { call.respondText { "c" } }
         }
    
         @Bean
         fun d(): KtorRouterFun = {
             get("/d") { call.respondText { "d" } }
         }
     }
    1. RoutingExtensionFun
     @Component
     class TestRouting { 
         fun Routing.e() {
             get("/e"){ call.respondText { "e" } }
         }
     }
  • module

    1. KtorModule
     @Component
     class TestModule : KtorModule { 
         override fun Application.install() {
             // ...
         }
     }
    1. KtorModuleFun (KtorModuleFun = Application.() -> Unit)
     @Component
     class TestModule {
         @Bean
         fun module(): KtorModuleFun = {
             // ...
         }
     }
    1. ApplicationExtensionFun
     @Component
     class TestModule { 
         fun Application.module() {
             // ...
         }
     }