Server-Side Kotlin with Ktor

May 21 2019 · Video Course (2 hrs, 31 mins) · Intermediate

Learn how to use the Ktor framework to build a Kotlin web app and API, and see how to deploy the app to the cloud and also run the app in a Docker container.

4.9/5 7 Ratings

Version

  • Kotlin 1.3, macOS 10.14, IntelliJ IDEA 2019.1

Getting Started with Ktor

Introduction

5:35 Free

Let's introduce Server-Side Kotlin and Ktor, discuss our sample project, and review all that you'll be learning in the course.

1

Hello, Ktor:

8:03 Free

You'll create a Ktor app from scratch in IntelliJ IDEA and add simple Hello World routes to the app.

2

App Routes

1:57 Free

In order to keep your code organized, you'll refactor the routes you've written so far so that each route has its own source file.

3

Test your knowledge about building app routes in Ktor by adding an about route to the web app, then see a solution.

4

Add a repository interface and in-memory repository implementation in order to save model EmojiPhrases in between requests to the app.

5

API Post Endpoint

1:06 Free

Create a POST endpoint to which you can send new EmojiPhrases, then test the endpoint using curl and a REST client app.

6

Get Route

2:00 Free

Add a GET route to the web app that will let you retrieve and see EmojiPhrases that have been add to the repository.

7

Introduce FreeMarker templating into the app and create a simple HTML page for showing your EmojiPhrases.

8

Conclusion

0:57

Review all that you've done in Part 1 of the course, and take a look ahead at where we'll be going in Part 2 and beyond.

9

Beautification and Type-Safe Routing

See what we'll be covering in Part 2: adding basic authentication, using Bootstrap components for styling, and adding type-safe routing.

10

Install the Ktor Authentication feature into your app and add Basic Authentication to the POST route and GET route for phrases.

11

Build an HTML form to let users post new EmojiPhrases directly from the app instead of using other REST clients.

12

Get an introduction to the Bootstrap open-source front-end framework, and review the Bootstrap code that has been added to the app FreeMarker templates.

13

Setup static content in your Ktor web app, and complete the process of adding Bootstrap to the Home and Phrases pages of the app.

14

Test your knowledge of FreeMarker and the use of Bootstrap by completing the EmojiPhrases app About page, then see a solution.

15

Install the Ktor Locations feature into the app, then use the feature to switch to using type-safe routing.

16

Conclusion

1:02

Review all that you've done in Part 2 of the course, and take a look ahead at where we'll be going in Part 3 and beyond.

17

Persistence and Sessions

See what we'll be covering in Part 3 of the course, adding true data persistence using Exposed and PostgreSQL and building in real authentication via sessions.

18

Add the Exposed SQL library framework from JetBrains into the app, and use it with an in-memory H2 database and with database connection pooling.

19

PostgreSQL

4:20

Switch from using H2 with Exposed to instead using PostgreSQL, adding true data persistence so that data is saved between different runs of the app.

20

Learn about user authentication via cookies and sessions, understand the purpose of password hashing, and begin to add user sessions into the course app.

21

Continue adding sessions into the course app by creating the code for the sign up and sign in pages of the app.

22

Finish adding sessions into the app by checking for active sessions on the different pages of the app, and verifying a session when users post new data.

23

Conclusion

0:44

Review all that we've done in Part 3 of the course and take a look at where we'll be going in Parts 4 and 5.

24

JWT Auth and the API

See what we'll be covering in Part 4 of the course, adding JSON Web Tokens for API authentication and completing a phrases API for the app.

25

Learn about JSON Web Tokens and how they are used, and then add a login endpoint from which API users can obtain a JWT.

26

Create a GET endpoint in the API from which API users can request the EmojiPhrases stored in the app repository.

27

Create a POST endpoint in the API to which API users can send new EmojiPhrases, and test adding data in the Postman REST client.

28

Conclusion

0:52

Review all that we've done in Part 4 of the course and take a look at where we'll be going in Part 5.

29

Deployment

See what we'll be covering in Part 5 of the course, deploying our Ktor app to Heroku, creating a Docker image, and running the Docker image in a container.

30

See how to deploy your Ktor app to Heroku, connect Heroku to GitHub, and setup a PostgreSQL database on Heroku for your app.

31

Add some build flags to support Dockerizing your Ktor app, then write a Dockerfile and use it to build a Docker image of the app.

32

Run your Ktor app Docker image in a container, including connecting the app container to a Docker container running PostgreSQL.

33

Conclusion

2:43

Review all that you've done to build a deployable Ktor web app and API, both backed by a PostgreSQL database, and take a look at where to go from here.

34

Who is this for?

This course is for Kotlin and Android developers interested in learning how to use Kotlin on the server to build a web app and a web API. It expects you to be familiar with the Kotlin language and either Android Studio or IntelliJ IDEA. You'll also need basic knowledge of how HTTP works and have some experience with use of the command-line.

Covered concepts

  • Creating a Ktor web app
  • Building a REST API with Ktor
  • Type-safe routing in a Ktor app
  • HTML Templating with FreeMarker
  • Using Bootstrap with FreeMarker
  • The Exposed SQL Library
  • Using PostgreSQL with Ktor
  • Session and Cookie Authentication
  • JSON Web Token Authentication
  • Deploying a Ktor app to Heroku
  • Dockerizing a Ktor app

Contributors

Comments