Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
サーバサイドKotlinへの入門 Ktor編
Search
虎の穴ラボ株式会社
June 06, 2019
Technology
1.6k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
サーバサイドKotlinへの入門 Ktor編
虎の穴ラボ株式会社
June 06, 2019
More Decks by 虎の穴ラボ株式会社
See All by 虎の穴ラボ株式会社
関西Ruby登壇資料
toranoana
0
38
Tailwind CSSとAtomic Designで実現する効率的な Web 開発の事例
toranoana
1
720
Denoについて、同人誌記事を出しました+update
toranoana
0
250
【虎の穴ラボ Tech Talk #2】プロンプトエンジニアリング
toranoana
0
170
20241121_[TechTalk#2]虎の穴ラボでのLLMについて取り組み紹介
toranoana
0
180
社内チャットへRAG導入した話(Tech Talk #2)
toranoana
0
250
Deno Deploy で Web Cache API を 使えるようになったので試した知見
toranoana
1
780
【虎の穴ラボ Tech Talk】虎の穴ラボTech Talk説明資料
toranoana
0
540
虎の穴ラボ Tech Talk_CDKでFargate環境構築
toranoana
1
710
Other Decks in Technology
See All in Technology
Code for Security プロジェクト紹介 2026年10月
yu23ki14
0
110
USB PDを使ってスマホを労わりたい
raspython3
0
180
CTO Night|NotionのAIエージェントとFDE
kzkhykw1991
0
230
スキマバイトという雇用形態は存在しないので、雇用期間1日のアルバイト契約を事業者とワーカーが結ぶ手続きを支えるのがタイミーなんです
akitoshiga
0
210
Optunaの最新リリースv5.0について
pfn
PRO
0
120
Benchmarking Disaggregated Serving on vLLM + Dynamo with a Real Coding-Agent Workload
nttcom
1
200
専門領域のAIをどう評価するか
bengo4com
2
290
アウトプット初心者、半年間のふりかえり
4o1sobblue
0
440
V8のArray.prototype.flatを最大約20倍速くするまでと、巨大OSSへの大規模コミットの道のり
riyaamemiya
0
310
AI導入は済んだ。次は統制を作り替える番だ_AI×開発組織 Summit 2026
techtekt
PRO
0
360
Rust で関数型ドメインモデリング
takonda
0
170
Gemini Intelligence 入門 ― AppFunctions と Gemini Nano
takuroabe
0
290
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
260
RailsConf 2023
tenderlove
30
1.6k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Statistics for Hackers
jakevdp
799
230k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
530
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
WCS-LA-2024
lcolladotor
0
890
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Product Roadmaps are Hard
iamctodd
55
13k
Transcript
Kotlin
Ktor 1 Copyright © 2019 Toranoana Inc. All Rights Reserved.
,' ,' ,' ,' , ' ,' +) %" #(
• 2019 3!& • *Java • .- /$ • – 0 – & 2 Copyright © 2019 Toranoana Inc. All Rights Reserved.
1.
Kotlin 2. 3. Ktor 4. (Routing) 5. (Locations) 6. Basic! (Authenticaton) 7. 3 Copyright © 2019 Toranoana Inc. All Rights Reserved.
% $ % $ % $ % $ % $
% $ 1.Kotlin # *" →SparkFramework!Java/Kotlin Java & Kotlin*"+ Java '() 4 Copyright © 2019 Toranoana Inc. All Rights Reserved.
. + . + . + . + . +
. + 2.) • Ktor JetBrains*# Web 1.0.02018"11$ (! 1.2.1(2019/5/27) Kotlin)1 %&, 0/ '-Features# 5 Copyright © 2019 Toranoana Inc. All Rights Reserved.
3.Ktor https://start.ktor.io/ 6
Copyright © 2019 Toranoana Inc. All Rights Reserved.
3.Ktor IntellijKtor
7 Copyright © 2019 Toranoana Inc. All Rights Reserved.
3.Ktor 9
Features Routing Locations Authentication Copyright © 2019 Toranoana Inc. All Rights Reserved.
+ ) + ) + ) + ) + )
+ ) 3.Ktor 10 fun main(args: Array<String>) { val server = embeddedServer(Netty, 8080) { this.module(false) } server.start(wait = true) } fun Application.module(testing: Boolean = false) { routing { get("/") { call.respondText("HELLO WORLD!", contentType = ContentType.Text.Plain) } } } Application.kt #'! $*"-& ,. "!!!/Netty "/8080 " HELLOWORLD! "%( Copyright © 2019 Toranoana Inc. All Rights Reserved.
3.Ktor 11 Copyright
© 2019 Toranoana Inc. All Rights Reserved.
4. (Routing)
12 Copyright © 2019 Toranoana Inc. All Rights Reserved. • /user/{name} {name}
4. (Routing)
13 fun Application.module(testing: Boolean = false) { routing { get("/") { call.respondText("HELLO WORLD!", contentType = ContentType.Text.Plain) } } get("/user/{name}") { val name = call.parameters["name"] ?: "" call.respondText("Hi! $name") } } http://localhost:8080/user/tora Hi! tora Copyright © 2019 Toranoana Inc. All Rights Reserved.
14 Copyright © 2019
Toranoana Inc. All Rights Reserved. 4.(Routing)
5. (Locations)
15 Copyright © 2019 Toranoana Inc. All Rights Reserved. • /type/{name} • /type/{name}/edit • /type/{name}/list/{page} type
5. (Locations)
16 fun Application.module(testing: Boolean = false) { install(Locations) { } routing { // Register nested routes get<Type> { type -> call.respondText("Inside $type") } get<Type.Edit> { edit -> call.respondText("Inside $edit") } get<Type.List> { list -> call.respondText("Inside $list") } } } @Location("/type/{name}") data class Type(val name: String) { @Location("/edit") data class Edit(val type: Type) @Location("/list/{page}") data class List(val type: Type, val page: Int) } http://localhost:8080/type/tora Type Copyright © 2019 Toranoana Inc. All Rights Reserved.
17 fun Application.module(testing:
Boolean = false) { install(Locations) { } routing { // Register nested routes get<Type> { type -> call.respondText("Inside $type") } get<Type.Edit> { edit -> call.respondText("Inside $edit") } get<Type.List> { list -> call.respondText("Inside $list") } } } @Location("/type/{name}") data class Type(val name: String) { @Location("/edit") data class Edit(val type: Type) @Location("/list/{page}") data class List(val type: Type, val page: Int) } http://localhost:8080/type/tora Type Copyright © 2019 Toranoana Inc. All Rights Reserved. 5. (Locations)
18 Type
nametora Copyright © 2019 Toranoana Inc. All Rights Reserved. 5. (Locations)
19 fun Application.module(testing:
Boolean = false) { install(Locations) { } routing { // Register nested routes get<Type> { type -> call.respondText("Inside $type") } get<Type.Edit> { edit -> call.respondText("Inside $edit") } get<Type.List> { list -> call.respondText("Inside $list") } } } @Location("/type/{name}") data class Type(val name: String) { @Location("/edit") data class Edit(val type: Type) @Location("/list/{page}") data class List(val type: Type, val page: Int) } NestLocation /type/{name}/edit /type/{name}/list/{page} 5. (Locations)
20 Edit
List Copyright © 2019 Toranoana Inc. All Rights Reserved. 5. (Locations)
'# '# '# '# ' # '# 6.Basic*)(Authenticaton) 21 fun
Application.module(testing: Boolean = false) { install(Authentication) { basic(name = "myauth1") { realm = "Ktor Server" validate { credentials -> if (credentials.name == credentials.password) { UserIdPrincipal(credentials.name) } else { null } } } } ( $) ($) routing { authenticate("myauth1") { get("/basic") { val principal = call.authentication.principal<UserIdPrincipal>() call.respondText("Hi ${principal?.name ?: ""}", contentType = ContentType.Text.Plain) } } } } *)! +myauth1 valiate *)!"%+ name password&( & Copyright © 2019 Toranoana Inc. All Rights Reserved.
! ! ! ! !
! 22 fun Application.module(testing: Boolean = false) { install(Authentication) { basic(name = "myauth1") { realm = "Ktor Server" validate { credentials -> if (credentials.name == credentials.password) { UserIdPrincipal(credentials.name) } else { null } } } } ( ) ( ) routing { authenticate("myauth1") { get("/basic") { val principal = call.authentication.principal<UserIdPrincipal>() call.respondText("Hi ${principal?.name ?: ""}", contentType = ContentType.Text.Plain) } } } } http://localhost:8080/basic Basic#" #"$ #" Copyright © 2019 Toranoana Inc. All Rights Reserved. 6.Basic#"(Authenticaton)
23 Copyright ©
2019 Toranoana Inc. All Rights Reserved. 6.Basic(Authenticaton)
= : = : = : = : = :
= : 7. • Intellij Ktor#%( Ktor#' 6; • &)( 29A – ()! Routing – )%,8Locations "%$ .40 /5+7*> )%31Validation-< • @? Features82 24 Copyright © 2019 Toranoana Inc. All Rights Reserved.
25 Copyright © 2019 Toranoana Inc. All Rights Reserved.