If you are looking to build scalable web services or clients on the JVM then Ktor is for you. Written in Kotlin, this is an extensible, lightweight framework that uses coroutines to provide an easy to test and easy use asynchronous programming model.
Many web applications and services are built using the Spring Framework. While Spring is incredibly powerful and useful nobody can accuse it of being lightweight. Many developers look for something that ‘just works’, that does not have too much overhead. In this course, Building Web Applications in Kotlin Using Ktor, you will learn about the framework that more and more JVM developers are looking at as a programming language because of the benefits it has such as support of immutable data and null detection, as well as having less of the bloat of Java. Bring these two together, a lightweight HTTP framework and a nice programming language and you get Ktor. First, you will explore Ktor - an open source project developed by JetBrains, the creators of Kotlin. It is heavily based on Kotlin coroutines and so supports a high degree of asynchrony. Next, you will discover how you can use Ktor to develop both REST and HTML based web sites that are secure and extensible. Finally, you will gain an understanding of how to produce complex server-based applications or standalone HTTP client applications. When you are finished with this course, you will know how to create web applications and REST APIs in Ktor.
Course Overview (Music) Hi everyone. My name is Kevin Jones, and welcome to my course, Building Web Applications in Kotlin Using Ktor. I am a developer and owner at Rock Solid Knowledge, a software development company based in the United Kingdom. Kotlin is a language that has taken the Java and Android worlds by storm. Ktor is an HTTP server and client framework built using Kotlin and written by JetBrains. This course is an introduction to developing Ktor applications. I concentrate mostly on server-side code, but also cover client-side topics. Some of the major topics we will cover include writing REST APIs, building websites using templates, rooting incoming requests based on verbs and HTTP headers, securing the web application and the REST API using OAuth, and using dependency injection, writing tests and mocking. By the end of this course, you'll know how to create securer, scalable, robust web applications and REST APIs in Ktor. Before beginning the course, you should be familiar with programming Kotlin. I hope you will join me on this journey to learn Ktor with the Building Web Applications in Kotlin Using Ktor course at Pluralsight.
Adding Services and Dependency Injection with Koin In the previous module, we added an HTML front end to the application. In this module, we'll add more services, and we'll take a look at how we set up the services and do dependency injection inside Ktor. So to do the dependent injection we'll use a library called Koin. So welcome back to the Building Web Applications in Kotlin with Ktor class. My name is Kevin Jones. So in this module, we'll first take a look at application design, so how these applications are going to be structured and how they're going to be layered. We need to cover testing as we set up these services, and we need to cover mocking. So we'll look at how we do mocking within Kotlin and within Ktor. We'll see how we add repositories and add services to our application, and we'll see that to do these things we need to use dependency injection, and to do dependency injection we're going to use Koin. So our application will be structured something like this. We have our web front end. That web front end is calling a REST service, and that REST service is getting its data from a database. Within the REST service itself we'll have two layers; we'll have the API layer that is exposed to the web front end, and we'll have the repository layer, and that repository layer is a thing that reaches out and gets the data. So we need to set up these two layers, the API layer and the repository layer within the REST application itself. So let's see how we do that now.
Securing the REST API So in the previous modules, we looked at how we secured the HTML front end to the application, and we looked at how we could add sessions to the application. Now that we have those two pieces in place, we can look at how we secure the REST API. Welcome back to the Building Web Applications with Kotlin in Ktor class; my name is Kevin Jones. So in this module, we're going to use something called JWT authentication from inside Ktor. Again, we're simply going to use OAuth, but this time we're going to use it to secure the REST API, and we'll secure it for use within our application and for anybody else that might want to use our REST API. So we're going to protect the API from unauthenticated users. So as we have most of the pieces in place for this, and we've seen most of the technology behind this, let's go and add that code now.