Slide 1

Slide 1 text

Kotlin Server-Side Development Using Ktor @chennevin

Slide 2

Slide 2 text

Agenda •Ktor •Android -> Backend

Slide 3

Slide 3 text

Ktor • Easy to Learn • Easy to Use • Client + Server • Features / Middleware • OAuth 2 - Firefox Account • Nice Architecture • Routing + Controller

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

start.ktor.io

Slide 6

Slide 6 text

start.ktor.io

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Intellij Plugin

Slide 9

Slide 9 text

Auto Sync….

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

My First Server

Slide 12

Slide 12 text

Respond Text

Slide 13

Slide 13 text

Respond… JSON?

Slide 14

Slide 14 text

Content Negotiation

Slide 15

Slide 15 text

Content Negotiation

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Getting Parameters

Slide 18

Slide 18 text

Features (Middleware)

Slide 19

Slide 19 text

Firefox Account • Internal only— Coming soon! API DOC • OAuth 2.0 (authentication grand type) • authorization • token • profile

Slide 20

Slide 20 text

Ktor Auth (Oauth)

Slide 21

Slide 21 text

Ktor Auth (Oauth)

Slide 22

Slide 22 text

Retrofit :)

Slide 23

Slide 23 text

Architecture (MVC) • RSS API

Slide 24

Slide 24 text

Architecture (Route)
 https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/routes •

Slide 25

Slide 25 text

Route VS Controller

Slide 26

Slide 26 text

Routing HelloRoute.kt

Slide 27

Slide 27 text

Google App Engine • Build highly scalable applications on a fully managed serverless platform • Java 8 + Jetty9 • Java 11 (Beta)+Netty • Sample: Mobile app backend services

Slide 28

Slide 28 text

Google App Engine • Build highly scalable applications on a fully managed serverless platform • Java 8 + Jetty9 • Java 11 (Beta)+Netty • Sample: Mobile app backend services

Slide 29

Slide 29 text

Ktor on App Engine • Follow the document Follow Ktor Doc

Slide 30

Slide 30 text

Add GAE Manually(1)

Slide 31

Slide 31 text

Add GAE Manually(2)

Slide 32

Slide 32 text

Ktor Good Read • Mobile Backends (IO 2019)
 https://www.youtube.com/watch? v=zjWOMBdPbsI&t=517s • KotlinConf Ryan Harter 
 https://www.youtube.com/watch?v=V4PS3IjIzlw

Slide 33

Slide 33 text

Exception Handling[link]

Slide 34

Slide 34 text

• Don’t make exception a part of your business logic • Don’t abuse GlobalExceptionHandler • Use standard Exception • Kotlin doesn’t have checked exception • Cleaner code • Need to look into library method that throws Exception Handling[link]

Slide 35

Slide 35 text

Exception Handling • Don’t make exception a part of your business logic • Don’t abuse GlobalExceptionHandler • Use standard Exception • Kotlin doesn’t have checked exception • Cleaner code • Need to look into library method that throws

Slide 36

Slide 36 text

(Android Dev)->Backend Dev Diff Same RAM IoC Async Testing Killed Application Context Error

Slide 37

Slide 37 text

Annotation Use-site Targets •

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

Armeria • HTTP/2 RPC/REST client/ server library • built on top of Java 8, Netty, Thrift and gRPC https://www.youtube.com/ watch?v=hLlctum1pIA

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

Ktor Route Creation • Extension functions

Slide 53

Slide 53 text

Ktor Route Creation • Extension

Slide 54

Slide 54 text

Ktor Route Creation • Extension Configure

Slide 55

Slide 55 text

Spring Controller Creation

Slide 56

Slide 56 text

Spring Handling Request

Slide 57

Slide 57 text

Ktor Handling Request

Slide 58

Slide 58 text

Take away • Ktor • Introduction • Request / Respond • Features • Firefox Account • Architecture • Deploy to Google App Engine • Backend development for Android dev • Exception Handling • Annotation Use-site Targets • Final / Nullable • Spring / Armeria / Ktor

Slide 59

Slide 59 text

Suggestions… • Use Ktor GAE samples • Use Groovy Gradle build script for now • Be careful fo Intellij 2019.2 (don’t touch offline mode!)

Slide 60

Slide 60 text

Thank you! @chennevin