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
33
Tailwind CSSとAtomic Designで実現する効率的な Web 開発の事例
toranoana
1
710
Denoについて、同人誌記事を出しました+update
toranoana
0
240
【虎の穴ラボ 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
760
【虎の穴ラボ Tech Talk】虎の穴ラボTech Talk説明資料
toranoana
0
530
虎の穴ラボ Tech Talk_CDKでFargate環境構築
toranoana
1
700
Other Decks in Technology
See All in Technology
Claude in Chrome 入門 / Introduction to Claude in Chrome
cielo1985
0
870
登壇の自信を奪う3匹のオバケ / 3 Ghosts That Rob You of Your Confidence in Public Speaking
pauli
9
1k
C#未経験の僕がAIに読めるコードを書かせるまで
maguroalternative
0
110
AgentCore Runtime上にAgentic Coding基盤を構築・展開する際の設計ポイントと限界点 / Design considerations and limitations when building an agentic coding platform on AgentCore Runtime
har1101
5
470
AIで社員の自主発信に広報目線を組み込む
_mossann_t
0
130
AI 時代のスタートアップエコシステ厶から考究する技術的負債との向き合い方
m3m0r7
PRO
3
2.3k
.NET WebAssemblyで実現するクライアントサイドAI推論:NuGetからViteまで、2つのエコシステムを繋ぐビルド戦略
yamachu
0
250
サーバーレスをどこまで使う? WebRTC対戦ゲームで選んだVPSとの共存設計
kaidouji85
0
180
ADKで始める業務改善 - AIエージェント開発時の考えと設計
harappa80
2
240
AIによるクリエイティブ生成を行う上での試行錯誤
plaidtech
PRO
0
160
事業課題から技術的負債に向き合う
sansantech
PRO
2
2k
AI時代、データエンジニアが一番おもろい
genshun9
0
670
Featured
See All Featured
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
540
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
460
Building an army of robots
kneath
307
46k
Rails Girls Zürich Keynote
gr2m
96
14k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
830
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
260
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
How to Think Like a Performance Engineer
csswizardry
28
2.8k
Facilitating Awesome Meetings
lara
57
7.1k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
340
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
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.