Hands-On Kotlin Web Development with Ktor

Video description

Build web apps quickly and with less effort using Kotlin and Ktor

About This Video

  • Create a lightweight REST-enabled backend from scratch for use on your website or mobile app
  • Understand the Ktor lifecycle and how to apply plugins to develop a bookstore app and master core app development
  • Create a Ktor project from scratch and get started with Kotlin coroutines and Kotlin class extensions

In Detail

Ktor is a Kotlin-specific framework for building asynchronous client- and server-side web applications. It is one of the most widely-adopted and supported alternatives to Java for Android app development. Ktor has gained massive popularity remarkably quickly, and you'll rapidly create connected applications in Kotlin with minimal effort.

This course provides hands-on training in a practical and engaging way to get you started building an end-to-end web application using Kotlin's popular framework, Ktor. You will begin by swiftly covering Kotlin and Ktor basics (for this, you'll benefit from some basic knowledge of Kotlin before starting this course).

You'll cover setting up your project-which will be full-stack (client and server)—and create your web application in the Ktor framework using Kotlin as your language. You'll cover some important Ktor features and solutions, and will cover routing and HTML Builder. You'll also run your configured application and test it.

By the end of the course, you will have learned how to build web applications with Kotlin using the Ktor framework.


This course is suitable for Java, Kotlin, and Android developers who want to use the Ktor framework, which is quickly gaining popularity when it comes to building client- and server-side web applications. A basic knowledge of Kotlin will be required.

Publisher resources

Download Example Code

Table of contents

  1. Chapter 1 : Getting Started with Kotlin and Ktor
    1. The Course Overview
    2. What is a backend
    3. Why choose Ktor as backend?
    4. Creating our first project with IntelliJ plugin and ktor.start.io
    5. Creating our first route that returns a string
    6. Bookstore-application: Create and set up dependencies
  2. Chapter 2 : Understanding the Ktor Lifecycle
    1. Kotlin coroutine explained and demonstrated
    2. Kotlin Extension explained and demonstrated
    3. Ktor architecture and lifecycle explained
    4. Ktor installation and configuration of features
    5. Ktor routes in general
    6. Calling 3rd party REST services
    7. Endpoints for our book store. Get and post books
    8. The PUT,POST,GET and DELETE Routes
    9. Let Us Test the Endpoints with cURL
  3. Chapter 3 : Working with Ktor REST API
    1. Creating a REST API
    2. Feature Content Negotiation
    3. Conversion from Kotlin object to JSON with Jackson
    4. Auto-update web application on build
    5. Routes with path variables
    6. Routes with request parameters
    7. Getting and setting headers
    8. Bookstore-application: Convert json to objects. Add search endpoints with request parameters
  4. Chapter 4 : Ktor REST API - Error handling and authentication
    1. Feature Status Pages
    2. Data posted to the route endpoint
    3. Basic Authentication on chosen endpoints
    4. Routing interceptors - Check admin rights
    5. CallLogging log all incoming requests
    6. Metrics statistics on the usage of the endpoints
    7. Bookstore-application: Add error handling and basic authentication to our book store
  5. Chapter 5 : Persisting data with MongoDB
    1. Starting up a MongoDb with Docker-compose and adding the MongoDB dependency
    2. Insert data to a MongoDB
    3. Updating and deleting data
    4. Extracting data with a query
    5. Sorting and paging
    6. Bookstore-application: Saving, deleting and extracting books
  6. Chapter 6 : Testing the Ktor application
    1. Test strategy - No server context needed
    2. Setting up a Ktor test
    3. What is a good unit test
    4. Performance testing with K6
    5. Bookstore-application: Setup K6 and unit tests
  7. Chapter 7 : A web UI with Ktor - HTML and CSS DSL
    1. HTML DSL - Installing the feature and writing basic HTML
    2. HTML DSL importing css
    3. HTML DSL importing static files
    4. CSS DSL - Installing the feature and writing basic CSS
    5. CSS DSL rules
    6. HTML Templating and passing variables
    7. Bookstore-application: Create a login page
    8. Bookstore-application: Create a Book search page
    9. Bookstore-application: Create a Cart checkout page
    10. Bookstore-application: Create receipt page
  8. Chapter 8 : Prepare for deployment
    1. Create a .jar file With Gradle
    2. Docker multi-stage build - Build image
    3. Docker multi-stage build - Execution image
    4. Bookstore-application: Create a docker image and spin it up

Product information

  • Title: Hands-On Kotlin Web Development with Ktor
  • Author(s): Mike Møller Nielsen
  • Release date: June 2020
  • Publisher(s): Packt Publishing
  • ISBN: 9781838640767