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๋ฅผ ๊ฒฐํฉํ ํ ์ด ํ๋ก์ ํธ๋ฅผ ์งํํด๋ณผ ์์ ..