LoginSignup
6
4

More than 5 years have passed since last update.

Ktor で Hello World までのメモ

Posted at

Ktor で Hello World までやってみたメモです。この記事にはほとんど何の情報もありませんが、これから初めたい方の手助けに少しでもなれば幸いです。

IntelliJ IDEA のダウンロード

IDE として IntelliJ IDEA のサイトから IntelliJ IDEA の Community 版 をダウンロードします(Free)。

Ktor プラグインのインストール

IntelliJ IDEA の開始画面で [Configure] -> [Plugins] を選択し、Ktor のプラグインを検索・インストールします。

スクリーンショット 2018-12-10 14.44.30.png

Ktor のプロジェクトの作成

IntelliJ IDEA の開始画面の [Create New Project] から下図のように Ktor のプロジェクトが作成できるので、適当に最後まで進んでプロジェクトを作成します。

スクリーンショット 2018-12-10 14.46.54.png

作成されたプロジェクト内の Application.kt を次のように編集し、

Application.kt
package com.example

import io.ktor.application.*
import io.ktor.response.*
import io.ktor.routing.get
import io.ktor.routing.routing

fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)

@Suppress("unused") // Referenced in application.conf
@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
    routing {
        get("/") {
            call.respondText("Hello World")
        }
    }
}

main 関数の横の再生ボタンを押下します。

スクリーンショット 2018-12-10 15.01.53.png

次のようにメッセージが表示されるので、メッセージ最後の http://0.0.0.0:8080 にブラウザでアクセスします。

スクリーンショット_2018-12-10_14_58_42.png

スクリーンショット 2018-12-10 15.02.25.png

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4