8
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Kanaryを使ってみた!

Last updated at Posted at 2017-12-19

Kanaryって?

GithubのReadmeによる 「A minimalist Kotlin web framework for building scalable and expressive RESTful APIs」で、簡単に言うとKtorみたいなweb frameworkです!

Kanary Logo

Ktorとかなり似てますので比べましょう!

Install

まぁ、どっちもインストールしやすいですね!

Ktor.kt
embeddedServer(Netty, 8080)
    .start(wait = false)
Kanary.kt
val app = KanaryApp()
val server = Server()
server.handler = AppHandler(app)
server.listen(8081)

両方とも簡単にインストール出来ます。だが、これじゃ何も動かない。

Handling requests

シンプルなケースを見ると

Ktor.kt
install(Routing) {
    route("hello") {
        get("/world") {
            call.respondText("Hello, World!", status = HttpStatusCode.OK)
        }
    }
}
Kanary.kt
val router = KanaryRouter("/hello")
router.get("/world",
    {_, _, response ->
        response withStatus 200 send "Hello, World!"
    }
)
app.mount(router)

Kanaryの方は英語っぽくかけるが、Ktorの方が全体的に読みやすいかな?
確かにKanaryの infix notation が読みやすく見えますね

response withStatus 200 send "Hello, World!"

Overall

KanaryもKtorも使いやすいので、ご遠慮なく使ってみてください!
Kanaryのいい点

  • インストールはまあまあ簡単
  • infix notation は読みやすい
  • ライフサイクルコールバックある (beforeAction() afterAction())
8
2
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
8
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?