Ktor?

Ktor๋Š” ๊ฐ•๋ ฅํ•œ Kotlin ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋น„๋™๊ธฐ ์„œ๋ฒ„ ๋ฐ ํด๋ผ์ด์–ธํŠธ๋ฅผ ๊ตฌ์ถ•ํ•˜๊ธฐ ์œ„ํ•œ ํ”„๋ ˆ์ž„์›Œํฌ
์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‰ฝ๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋„๋ก ์„ค๊ณ„๋˜์–ด์žˆ๋‹ค.
kotlin ๋ฒ ์ด์Šค ์ธ๊ฒƒ์„ ๋ด์„œ ์œ ์ถ”ํ•ด๋ณผ ์ˆ˜ ์žˆ๊ฒ ์ง€๋งŒ ํ•ด๋‹น ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ๋งŒ๋“  ๊ณณ์ด ๋ฐ”๋กœ JetBrain..

Ktor์— ๊ด€์‹ฌ์ด ์ƒ๊ธด ์ด์œ 

  • ๋…์ ์ ์ธ ํ”„๋ ˆ์ž„์›Œํฌ๋กœ ์Šคํ”„๋ง์ด ์ด๋ฏธ ์žˆ์ง€๋งŒ, kotlin ๋ฒ ์ด์Šค์˜ ๊ฒฝ๋Ÿ‰ํ™” ํ”„๋ ˆ์ž„์›Œํฌ์ธ ktor์„ ์‚ฌ์šฉํ•ด ๋ณด๊ณ  ์‹ถ์—ˆ์Œ.

  • ๊ธฐ๋ณธ์ ์œผ๋กœ ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ (spring reactor/webflux ์™€ ์–ผ๋งˆ๋‚˜ ์ฐจ์ด์ ์ด ์žˆ๋Š”์ง€.. ๊ถ๊ธˆํ–ˆ์Œ)

  • ์ปค์Šคํ„ฐ๋งˆ์ด์ง• ๊ฐ€๋Šฅ (spring์€ ์‚ฌ์‹ค์ƒ ํ”„๋ ˆ์ž„์›Œํฌ ์ž์ฒด๋Š” ์ปค์Šคํ„ฐ๋งˆ์ด์ง•์ด ์–ด๋ ค์šด ๊ตฌ์กฐ์—ฌ์„œ.. ktor์€ ์ž์œ ๋„๊ฐ€ ๋‹ค๋ฅธ๊ฐ€? ๊ถ๊ธˆํ–ˆ์Œ)

  • Kotlin๊ณผ ์‰ฝ๊ฒŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅ (java / kotlin ๋ชจ๋‘ ์‚ฌ์šฉํ•˜์ง€๋งŒ kotlin ์œ„์ฃผ๋กœ ๊ฐœ๋ฐœ์„ ๋” ๋งŽ์ด ํ•ด๋ณด๊ณ  ์‹ถ์Œ)

Ktor ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ ๋ฐฉ๋ฒ•

๋‹ค์Œ ๋‹จ๊ณ„์— ๋”ฐ๋ผ ๊ฐ„๋‹จํ•œ Ktor ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑ:

1๋‹จ๊ณ„: Gradle ์„ค์ •

ํ”„๋กœ์ ํŠธ๋ฅผ ์œ„ํ•œ ์ƒˆ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๋งŒ๋“ค๊ณ  ๋‹ค์Œ build.gradle.kts ํŒŒ์ผ์„ ์ถ”๊ฐ€:

plugins {
    kotlin("jvm") version "1.5.21"
    id("io.ktor.plugin") version "1.6.3"
}
 
group = "com.example"
version = "0.0.1"
 
application {
    mainClass.set("com.example.ApplicationKt")
}
 
repositories {
    mavenCentral()
}
 
dependencies {
    implementation("io.ktor:ktor-server-core:1.6.3")
    implementation("io.ktor:ktor-server-netty:1.6.3")
    testImplementation("io.ktor:ktor-server-tests:1.6.3")
    testImplementation("org.jetbrains.kotlin:kotlin-test-junit:1.5.21")
}

2๋‹จ๊ณ„: ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ปจํŠธ๋กค๋Ÿฌ(main) ์ƒ์„ฑ

src/main/kotlin/com/example ๋””๋ ‰ํ† ๋ฆฌ์— Application.kt ํŒŒ์ผ์„ ์ƒ์„ฑ:

package com.example
 
import io.ktor.application.*
import io.ktor.http.*
import io.ktor.response.*
import io.ktor.routing.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
 
fun main() {
    embeddedServer(Netty, port = 8080) {
        routing {
            get("/") {
                call.respondText("Hello, Ktor!", ContentType.Text.Plain)
            }
        }
    }.start(wait = true)
}

3๋‹จ๊ณ„: ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰

๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰:

./gradlew run

๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ถœ๋ ฅ์„ ํ™•์ธํ•ด๋ณผ ์ˆ˜ ์žˆ๋‹ค.:

> Task :run
[main] INFO Application - Responding at http://0.0.0.0:8080

์šฐ์„ ์ ์ธ ํ”„๋กœ์ ํŠธ create๋Š” ์œ„์˜ ๊ณผ์ •์„ ๋.

์กฐ๋งŒ๊ฐ„ Ktor์™€ Nuxt.js๋ฅผ ๊ฒฐํ•ฉํ•œ ํ† ์ด ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•ด๋ณผ ์˜ˆ์ •..