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
A Friendly Introduction to Ktor Server
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Ilker Aslan
March 12, 2023
Programming
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
A Friendly Introduction to Ktor Server
Ilker Aslan
March 12, 2023
More Decks by Ilker Aslan
See All by Ilker Aslan
Yet Another KMP*
ilkeraslan
0
310
Other Decks in Programming
See All in Programming
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
Railsバージョンを4倍にした話
optim
0
350
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
17k
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
28
32k
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
1
430
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
180
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
790
Workers Cache を知る
syumai
0
360
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
500
パスワード再設定メールのURLについて知っておこう
uyuki234
0
160
Featured
See All Featured
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1k
How to make the Groovebox
asonas
2
2.5k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
640
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
410
A Tale of Four Properties
chriscoyier
163
24k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.3k
Building the Perfect Custom Keyboard
takai
2
910
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
570
Rails Girls Zürich Keynote
gr2m
96
14k
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
Transcript
@@export_scripts@@ A FRIENDLY INTRODUCTION TO KTOR SERVER
@@export_scripts@@ What is Ktor? Framework for micro services, web applications,
and HTTP services – Open Source, by JetBrains – Based on Kotlin Coroutines (asynchronous) –
@@export_scripts@@
@@export_scripts@@ Self Contained Package Application controls the engine settings, connection,
and SSL options – Servlet Servlet container controls the application lifecycle and connection settings –
@@export_scripts@@ Your First Server fun main() { embeddedServer( factory =
Netty, port = 8080, host = "0.0.0.0", module = Application::module ) .start(wait = true) }
@@export_scripts@@
@@export_scripts@@ Application Engine Environment Connectors that describe where and how
server should listen. – The running application – start/stop functions –
@@export_scripts@@ Application Engine Configuration Current parallelism level (e.g. the number
of available processors) – Threads used for new connections, processing connections, parsing messages –
@@export_scripts@@ Modules public actual val modules: MutableList<Application.() -> Unit> =
mutableListOf() Extension functions of an Application to structure the plugins
@@export_scripts@@ fun Application.module() { install(Resources) install(StatusPages) install(RequestValidation) configureRouting() configureSerialization() }
@@export_scripts@@ fun Application.configureRouting() { routing { indexRoute() beerRoutes() } }
@@export_scripts@@ fun Route.indexRoute() { route("/") { get { call.respondText( text
= "Welcome", status = HttpStatusCode.OK ) } } }
@@export_scripts@@
@@export_scripts@@ Routing fun Route.beerRoutes() { route("/beer") { get {...} get("{name?}")
{...} get("{id?}") {...} post {...} put("{id?}") {...} delete("{id?}") {...} } }
@@export_scripts@@ Type Safe Routing fun Route.beerRoutes() { get<resources.Beer> {...} get<resources.Beer.Id>
{...} post<resources.Beer> {...} put<resources.Beer.Id> {...} delete<resources.Beer.Id> {...} }
@@export_scripts@@ Resources @Resource("/beer") class Beer( val name: String? = null
) { @Resource("{id}") class Id(val parent: Beer = Beer(), val id: Long) }
@@export_scripts@@ Resources To define a route handler for a typed
resource, pass a resource class to a verb function (get, post, put...). – Serializable by default –
@@export_scripts@@ Build Links from Resources val link = href(Beer.Id(id =
1))
@@export_scripts@@ Get Beers curl --header "Content-Type: application/json" \ "http://0.0.0.0:8080/beer"
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@ Response Model @Serializable data class Response<T>( val data: T?
= null, val errors: List<Error>? = null )
@@export_scripts@@ Create a Beer curl --header "Content-Type: application/json" \ --data
"{"name": "Bock"}" \ "http://0.0.0.0:8080/beer"
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@ Delete a Beer curl --header \ "Content-Type: application/json" \
--request DELETE \ "http://0.0.0.0:8080/beer/532..."
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@ SSL and Certificates Ktor uses Java KeyStore (JKS) as
a storage facility for certificates. – Self-signed certificates for testing purposes by calling buildKeyStore() . –
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@ fun main() { ... embeddedServer( factory = Netty, environment
= environment ).start(wait = true) }
@@export_scripts@@ Send HTML in Response
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@ Respond with HTML Form
@@export_scripts@@
@@export_scripts@@ Templates To respond, call the respondHtmlTemplate() . – To
create a template, implement the Template interface. – Inside templates, use Placeholder or TemplatePlaceholder . –
@@export_scripts@@ Conclusions
@@export_scripts@@
@@export_scripts@@
@@export_scripts@@ The Repository
@@export_scripts@@ Where To Stalk Me https://androiddev.social/@ilker https://github.com/ilkeraslan https://www.polywork.com/ilkeraslan https://www.linkedin.com/in/aslanilker/ https://blog.ilker.it/