Kotlin Server Side

SMILE EGBAI

ANDROID DEVELOPER @PAYLATERNG

@SMILEEGBAI (TWITTER & MEDIUM)

Line Up

  • Where can we use it
  • Why server side
  • Server side frameworks
  • Case study: ktor
  • Q&A

Where can we use it?

  • Android
  • iOS
  • Server
  • Web Front-end
  • Machine Specific

Why write Kotlin on server?

  • Functional Objective constructs
  • Fast development
  • Concise code with robust frameworks
  • Type & Null Safety

What do I gain as an Android Dev?

  • Keeping up-to date

  • One language

  • Our own fullstack

How does it work?

  • JAVASCRIPT

  • JVM

Transpilation to JS

What does Kotlin give us in Node.js

Type safety



  let a = [,,,]
  a.length     // -> 3
  a.toString() // -> ',,'

What does Kotlin give us in Node.js

  • Type safety
  • No Callback hell
fs.readdir(source, function (err, files) {
  if (err) {
    console.log('Error finding files: ' + err)
  } else {
    files.forEach(function (filename, fileIndex) {
      console.log(filename)
      gm(source + filename).size(function (err, values) {
        if (err) {
          console.log('Error identifying file size: ' + err)
        } else {
          console.log(filename + ' : ' + values)
          aspect = (values.width / values.height)
          widths.forEach(function (width, widthIndex) {
            height = Math.round(width / aspect)
            console.log('resizing ' + filename + 'to ' + height + 'x' + height)
            this.resize(width, height).write(dest + 'w' + width + '_' + filename, function(err) {
              if (err) console.log('Error writing file: ' + err)
            })
          }.bind(this))
        }
      })
    })
  }
})

What Kotlin gives us with JVM based servers

Spring & Vertex

  • Nullable information on spring annotations
  • Functional routing using kotlin DSL
  • Extensions for Rest Template and WebApi

Ktor

Is a framework built by JetBrains for creating Web applications in Kotlin, making use of coroutines for high scalability and offering an easy-to-use and idiomatic API.

  • Asynchronous in nature(Based of coroutines)
  • Application server written in Kotlin for Kotlin
  • Sponsored and developed by Jetbrains
  • CORS (Cross Origin Resource Sharing)

  • Content negotiation

  • GSON/Jackson

Keywords

MICRO-DEMO

Kotlin Server Side

By egbai mmumene

Kotlin Server Side

  • 39