In this course, we’ll be building a microservice in Kotlin, and by the end of this course, it will be deployed to the cloud.
The microservices will represent a cat hostel.
You’ll be able to add cats to its database, remove cats from it and list them.
Why cats hostel? Because as long as you know how to implement basic operations, you can build it for any kind of entities you need: supermarket orders, auction items, taxis, you name it. So, why not cats?
Why Kotlin?
- Modern, productive and highly pragmatic language
- Type safe
- Null-safe
- Generics that actually make sense
- Intuitive
- Extensible
- Highly concurrent: Kotlin uses coroutines on top of best-in-class JIT provided by the JVM, that makes it one of the most efficient and concurrent languages nowadays
- Rich ecosystem: be it PostgreSQL, Kafka or RabbitMQ, the most solid libraries are written for the JVM. And Kotlin is able to make use of all of them
Why this course?
There are many good tutorials and books about Kotlin programming language nowadays. But most of them make the assumption that you’re either and Android developer or at least familiar with Java programming language and its ecosystem.
This course make no such assumptions. If you’re and experienced PHP, Python, Ruby or NodeJS developer, with zero Java knowledge, this course was build with you in mind.
What you need to know:
Some kind of web technology, be it JavaScript, PHP, Ruby or Python. I expect you to be familiar with terms like Request, Response, JSON and HTTP headers at the very least.
Familiarity with Git. I’ll provide you with a link to the relevant branch on GitHub after most of the videos, and I’ll show you commands that I use, but I won’t dive deep into what they do.
Basic SQL and Docker knowledge is useful, but not mandatory.
What this course covers:
- Basics of Kotlin programming language
- Dependency management with Gradle
- Ktor web framework
- Testing with Kotlin
- Working with databases using Exposed DSL
- Running Kotlin inside Docker container and Docker Compose
- Deploying Kotlin to Heroku
- Exposing GraphQL API with Kotlin
What this course doesn’t cover:
- Coroutines
- Building UI in Kotlin
- CI tools
- Security
Each of them is a large topic by itself, and I wanted to keep this course as focused as possible, so you’ll be able to produce a working and well tested application in an hour or two.
Supporting CRUD operations
-
1Introduction
In this video I'll introduce myself and the course agenda.
This video also explains what kind of project we will be building, and what prior knowledge you need to have before starting this course.
-
2Java Ecosystem
In this video we'll cover:
Basic JVM terminology
JVM
JRE
JDK
Relation between JVM, Java and Kotlin
-
3"Hello World" in Kotlin
Project setup using IntelliJ IDEA CE
Writing "Hello World" in Kotlin
-
4Dependency management with Gradle
What is Gradle
How to add libraries to the project
Ktor library structure
-
5Ktor Web Framework
Starting Ktor Web Server
Routing
Working with JSONs in Kotlin
Reading request parameters
-
6Refactoring for Tests
Creating test files
Adding JUnit dependency for tests
Using @Test annotation
IntelliJ support for tests
Refactoring application into modules
-
7Basics of Testing in Kotlin
Starting test server
Comparing test results
Handling JSONs in tests
Parsing strings to JSONs using ObjectMapper
Extension functions in Kotlin
Checking response status code
Debugging the Router
Deployment
-
8Setting up database using Docker
Installing PostgreSQL using Docker
Basic environment variables for PostgreSQL inside Docker
-
9Adding new repository to Gradle
Adding a new repository to Gradle, so we can use Exposed library
-
10Connecting to database using Exposed
Connecting to a database from Kotlin code using Exposed
Defining tables with Exposed
-
11Populating the database
Creating subrouters
Adding POST endpoint for creating a cat
Connect subrouter to the main router
Adding test for creation logic
Setting headers in tests
Reading request body
Inserting data into database
-
12Fetching all entities from DB
Reuse utility methods across tests
Data classes in Kotlin
Fetching entities from database
Converting DB rows to data classes
-
13Making tests stable
Cleaning database between tests
Using helper methods
Writing queries with Exposed DSL
-
14Completing CRUD
Updating entities in the database
Deleting entities
GraphQL
-
15Dockerizing microservice
Installing Docker
Gradle Application plugin
Building Docker image
-
16Using Docker Compose
Structure of docker-compose.yml
Reading environment variables in Kotlin
Setting environment variables in Docker Compose
Setting environment variables in IntelliJ
-
17Deploying to Heroku
Installing Heroku CLI
Authenticating with Heroku
Creating application on Heroku
Using database addon
-
18Optimising container memory
Packaging Kotlin application into JAR
Multistage builds in Docker
-
19Finalising the project
Using DATABASE_URL
Connecting to cloud database
Checking application in the cloud
-
20Summary
Let's summarise what we've achieved in this course.