Ktor で hello world サーバーを立てるprojekto를 web で作成して IntelliJ で実行する
前提条件
IntelliJ 설치 도구
Web の Ktor Project Generator で Ktor 프로제크트を作成する
start.ktor.io의 사이트에 액세스
https://start.ktor.io/

この사이트에서 生成できる
Project 名を決定するとprojekt作成が始まる.
웹사이트와 Artifact をTekkito-に決める

웹사이트 と 유물?の사이트 URL?を求められる.
example.com, example.com.ktor1
にする.なんなのか不明なのでそのままにする.
--
Plugins をなしで決定して프로젝트파일을 DL

플러그인 はなしで作成.

すると、zip 파일로 DL される.
DL された Ktor 프로제크트の構成を見てみる
とりあえず解凍して構成を 나무 でみてみる.
$ tree
.
├── build.gradle.kts
├── gradle.properties
├── settings.gradle.kts
└── src
├── main
│ ├── kotlin
│ │ └── com
│ │ └── example
│ │ ├── Application.kt
│ │ └── plugins
│ │ └── Routing.kt
│ └── resources
│ └── logback.xml
└── test
└── kotlin
└── com
└── example
└── ApplicationTest.kt
gradle での通常設定ファail, bildo設定ファyl, propatifァyl
これらが뿌리 に入っていて
実際のアプリノコードや, ルーTING ファ イ ルは
src/main/kotlin/com/example/
Application.kt
plugins/Routing.kt
ここに入っている.
ktor アプリを実行する
ktor アプリを IntelliJ で開いて実行する
~/source/に ktor1/のディレクトリを作っ했습니다.
その中に先程の zip 파일을 exract して展開.
IntelliJ와 Kotlin 프로젝션을 함께 사용할 수 있습니다.

左上のtabの Run をクrickする とモーdarが開いて
今のアプリ、Application.kt の ApplicationKt を実行できる.
2022-06-20 00:50:43.738 [main] INFO ktor.application -
Autoreload is disabled because the development mode is off.
2022-06-20 00:50:43.765 [main] INFO ktor.application -
Application started in 0.067 seconds.
2022-06-20 00:50:43.918 [DefaultDispatcher-worker-1] INFO
ktor.application - Responding at http://0.0.0.0:8080
サーバーの起動logがみれた.
実際に 8080 をみてみると

Hello World が表示されていた.
Application.kt をみてみる
package com.example
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import com.example.plugins.*
fun main() {
embeddedServer(Netty, port = 8080, host = "0.0.0.0") {
configureRouting()
}.start(wait = true)
}
웹사이트 で設定して com.example という名前空間が
프로제크트노루트扱いになると推測.
ktor의 서버 라이브라리의 엔진과 netty를 임포트
../plugins에서 루팅을 가져오기
main의 내부로
Netty のサーバーライブラリを使って
port を 8080 に設定して
호스트 を 0.0.0.0 に設定して
루팅에 ../plugins/の中身の定義を持ってくる
そしてサーバーをスタートする.
기술은 Routing ファイルにあるようだ.
embeddedServer(Netty, port = 8081, host = "0.0.0.0")
항구 を一つ上げて再起動すると
2022-06-20 01:03:03.100 [DefaultDispatcher-worker-1] INFO ktor.application - Responding at http://0.0.0.0:8081

ちゃんと 8081 で動く.
plugins/Routings.kt をみてみる
これがるーting 파일.
package com.example.plugins
import io.ktor.server.routing.*
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.request.*
最初의 패키지는 は名前空間の現在地の宣言과 推測.
ktor の server の ライブラリを 使用する.
라우팅 と 응용 프로그램 と 응답 を使用.
http と 요청 はまだ使わない.
fun Application.configureRouting() {
// Starting point for a Ktor app:
routing {
get("/") {
call.respondText("Hello World!")
}
}
routing {
}
}
Application に入れる形で configureRouting を定義
라우팅 を使って, 루트 へのアクセスで
레스폰드의 기술로 "Hello World"가 있습니다.
call.respondText("Hello from Kotlin Ktor")

Tekistを変更すると、ちゃん과 反映された.

型が灰色の四角で出てくるのが便利.
なお、これもコードだと間違えて最初は消そうとしていた.
まとめ
웹과 ktor의 프로제크트의 제네레이타를 사용하다
無料版の IntelliJ でも ktor projekto를 DL することができた.
その프로젝트에는 無料版でもキチンと開いて、
하이라이트も動いて、実行もできた.
ktor의 프로젝트는
websiteName/Application.kt
websiteName/plugins/Routing.kt
この2つに動作コードが書かれている.
앱으로 포트와 호스트 の番号の定義와
라우팅 파일을 사용했던 Netty 서바의 이동
루팅으로는 path と対応する레스폰드
これらが書かれていた.
そして、IntelliJ から実行すると、
指定のport から アクセスできた.
次にやること
https://ktor.io/docs/testing.html#overview
TDD ってことで、testを書いていきます!
IntelliJ 先生の機能で、実際のファイルからさくっとtestを作れるらしい!
後半やること
https://blog.takehata-engineer.com/entry/how-about-using-ktor
この記事を参考に一通りやる
Reference
이 문제에 관하여(Ktor で hello world サーバーを立てるprojekto를 web で作成して IntelliJ で実行する), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://dev.to/kaede_io/ktor-puroziekutowo-web-dezuo-cheng-site-intellij-deshi-xing-suru-f7e
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
$ tree
.
├── build.gradle.kts
├── gradle.properties
├── settings.gradle.kts
└── src
├── main
│ ├── kotlin
│ │ └── com
│ │ └── example
│ │ ├── Application.kt
│ │ └── plugins
│ │ └── Routing.kt
│ └── resources
│ └── logback.xml
└── test
└── kotlin
└── com
└── example
└── ApplicationTest.kt
src/main/kotlin/com/example/
Application.kt
plugins/Routing.kt
ktor アプリを IntelliJ で開いて実行する
~/source/に ktor1/のディレクトリを作っ했습니다.
その中に先程の zip 파일을 exract して展開.
IntelliJ와 Kotlin 프로젝션을 함께 사용할 수 있습니다.

左上のtabの Run をクrickする とモーdarが開いて
今のアプリ、Application.kt の ApplicationKt を実行できる.
2022-06-20 00:50:43.738 [main] INFO ktor.application -
Autoreload is disabled because the development mode is off.
2022-06-20 00:50:43.765 [main] INFO ktor.application -
Application started in 0.067 seconds.
2022-06-20 00:50:43.918 [DefaultDispatcher-worker-1] INFO
ktor.application - Responding at http://0.0.0.0:8080
サーバーの起動logがみれた.
実際に 8080 をみてみると

Hello World が表示されていた.
Application.kt をみてみる
package com.example
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import com.example.plugins.*
fun main() {
embeddedServer(Netty, port = 8080, host = "0.0.0.0") {
configureRouting()
}.start(wait = true)
}
웹사이트 で設定して com.example という名前空間が
프로제크트노루트扱いになると推測.
ktor의 서버 라이브라리의 엔진과 netty를 임포트
../plugins에서 루팅을 가져오기
main의 내부로
Netty のサーバーライブラリを使って
port を 8080 に設定して
호스트 を 0.0.0.0 に設定して
루팅에 ../plugins/の中身の定義を持ってくる
そしてサーバーをスタートする.
기술은 Routing ファイルにあるようだ.
embeddedServer(Netty, port = 8081, host = "0.0.0.0")
항구 を一つ上げて再起動すると
2022-06-20 01:03:03.100 [DefaultDispatcher-worker-1] INFO ktor.application - Responding at http://0.0.0.0:8081

ちゃんと 8081 で動く.
plugins/Routings.kt をみてみる
これがるーting 파일.
package com.example.plugins
import io.ktor.server.routing.*
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.request.*
最初의 패키지는 は名前空間の現在地の宣言과 推測.
ktor の server の ライブラリを 使用する.
라우팅 と 응용 프로그램 と 응답 を使用.
http と 요청 はまだ使わない.
fun Application.configureRouting() {
// Starting point for a Ktor app:
routing {
get("/") {
call.respondText("Hello World!")
}
}
routing {
}
}
Application に入れる形で configureRouting を定義
라우팅 を使って, 루트 へのアクセスで
레스폰드의 기술로 "Hello World"가 있습니다.
call.respondText("Hello from Kotlin Ktor")

Tekistを変更すると、ちゃん과 反映された.

型が灰色の四角で出てくるのが便利.
なお、これもコードだと間違えて最初は消そうとしていた.
まとめ
웹과 ktor의 프로제크트의 제네레이타를 사용하다
無料版の IntelliJ でも ktor projekto를 DL することができた.
その프로젝트에는 無料版でもキチンと開いて、
하이라이트も動いて、実行もできた.
ktor의 프로젝트는
websiteName/Application.kt
websiteName/plugins/Routing.kt
この2つに動作コードが書かれている.
앱으로 포트와 호스트 の番号の定義와
라우팅 파일을 사용했던 Netty 서바의 이동
루팅으로는 path と対応する레스폰드
これらが書かれていた.
そして、IntelliJ から実行すると、
指定のport から アクセスできた.
次にやること
https://ktor.io/docs/testing.html#overview
TDD ってことで、testを書いていきます!
IntelliJ 先生の機能で、実際のファイルからさくっとtestを作れるらしい!
後半やること
https://blog.takehata-engineer.com/entry/how-about-using-ktor
この記事を参考に一通りやる
Reference
이 문제에 관하여(Ktor で hello world サーバーを立てるprojekto를 web で作成して IntelliJ で実行する), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/kaede_io/ktor-puroziekutowo-web-dezuo-cheng-site-intellij-deshi-xing-suru-f7e텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)