|
1 | 1 | # Introduction
|
2 | 2 |
|
3 |
| -In this hands-on, we will learn how to build a connected application consisting of a Kotlin/JVM server part, and a Kotlin/JS client part. This includes providing simple JSON API, as well as consuming this API from a Kotlin + React application running in the browser. |
| 3 | +In this hands-on, we will build a connected application consisting of two parts: |
4 | 4 |
|
5 |
| -We structure our application as a Kotlin multiplatform project. Throughout the hands-on, we will see how this allows us to manage both server and client from within the same Gradle project, and keep an overview of our whole system from within our IDE. We will also explore how multiplatform projects enable us to share code and data models between client and server in our application. This will help us to make sure that our whole system is consistent, and lets us avoid duplicating code unnecessarily. |
| 5 | +- A server, using Kotlin/JVM |
| 6 | +- A web client, using Kotlin/JS |
6 | 7 |
|
7 |
| -By using popular Kotlin multiplatform libraries such as `kotlinx.serialization`, `kotlinx.coroutines`, and the `ktor` framework for API server and client, we will see how we can keep our application concise, performant, and type-safe – *even when communicating across network boundaries*. |
| 8 | +We will build a simple JSON API, and learn how to use the API from a web app using Kotlin & React. |
8 | 9 |
|
9 |
| -For this hands-on, you are expected to have an understanding of Kotlin. Some knowledge about basic concepts in React and Kotlin Coroutines may be helpful in understanding some of the sample code, but is not strictly required. |
| 10 | +We write both parts of the project together, as one Kotlin Multiplatform project. |
| 11 | +This will allow us to manage both server and client from within the same Gradle project, and keep an overview of our whole system from within our IDE. |
| 12 | +It's also a great way to learn more about code and data model sharing between client and server for our app. |
| 13 | +This will help us to make sure that our whole system is consistent, and lets us avoid duplicating code unnecessarily. |
| 14 | + |
| 15 | +By using popular Kotlin multiplatform libraries such as [`kotlinx.serialization`](https://github.com/Kotlin/kotlinx.serialization), [`kotlinx.coroutines`](https://github.com/Kotlin/kotlinx.coroutines), and the [Ktor](https://ktor.io/) framework for API server and client, we will build an app that is concise, performant, and type-safe – *even when communicating across network boundaries*. |
| 16 | + |
| 17 | +For this hands-on, you are expected to have an understanding of Kotlin. Some knowledge about basic concepts in React and Kotlin Coroutines may be helpful in understanding some sample code, but is not strictly required. |
10 | 18 |
|
11 | 19 | ### What we will build
|
12 | 20 |
|
13 |
| -When going out to the supermarket, it's always good to know what we want to buy, rather than rely on impulse purchases. That's how you end up with candy and chips, and not enough fruits and vegetables! So, for our demo application, we will build a simple shopping list application that allows us to plan out our groceries. |
| 21 | +When going out to the supermarket, it's always good to know what we want to buy, rather than rely on impulse purchases (That's how you end up with candy and chips, and not enough fruits and vegetables!) |
| 22 | + |
| 23 | +So, for our demo application, we will build a simple shopping list application that allows us to plan out our groceries. |
14 | 24 |
|
15 |
| -In the interest of concise and easy to understand code, we will keep the user interface of our application quite simple: a list of planned purchases and a field to enter any new shopping plans. By clicking on an element in our shopping list, we automatically remove it. |
| 25 | +To focus on the essentials, we will keep the user interface simple: a list of planned purchases and a field to enter new shopping items. By clicking on an element in the shopping list, it gets removed. |
16 | 26 |
|
17 |
| -Because not all purchases might be equally important, we also allow our users to specify a priority level. Simply by entering a number of exclamation points `!` to their shopping list entry, the user can assign a priority to the item. We'll also make sure that the list is always ordered, so that we can see the most important entries first. |
| 27 | +We'll also allow the user to specify a priority level for list entries. |
| 28 | +By adding an exclamation point `!` to an item, it gets a higher priority. |
| 29 | +We'll use this information to order the shopping list. |
18 | 30 |
|
19 | 31 | 
|
20 | 32 |
|
21 |
| -To achieve all this functionality, we will first build a small backend that serves a JSON API. Afterwards, we will use the data served by this API to populate our simple web interface. Last but not least, we'll expand the server of the application to include a proper database, to make sure that our data persists even across multiple reloads and restarts of the application. |
| 33 | +There's a lot ahead of us! First, we need to build a small backend that serves a JSON API. Then, we need to build our web interface which consumes that API. |
| 34 | +An a bonus, we'll also expand the server of the application to include a proper database, making data persistent across multiple reloads and restarts of the application. |
22 | 35 |
|
23 |
| -To make the app available even while we're standing in the supermarket, we'll also cover how to deploy the shopping list to a cloud provider in the last chapter. |
| 36 | +We'll also talk about how to deploy the shopping list to a cloud provider in the last chapter (so that while we're standing in the supermarket, the app will still be available). |
24 | 37 |
|
25 |
| -Before we dive in and start coding our application, let's talk for a brief moment about why choosing a Kotlin multiplatform architecture for such a type of project can be beneficial. |
| 38 | +Before we dive in and start coding our application, let's talk about why choosing Kotlin Multiplatform for this project can be beneficial. |
26 | 39 |
|
27 | 40 | ### Benefits of a multiplatform architecture
|
28 | 41 |
|
29 |
| -We will write this whole application in Kotlin: the backend will use Kotlin/JVM, the frontend will use Kotlin/JS. This has a number of benefits: besides syntax, it also allows us to share our libraries and programming paradigms (such as using coroutines for concurrency), on both frontend and backend. |
| 42 | +When we're done, the whole app will be written in Kotlin: the backend will use Kotlin/JVM, the frontend will use Kotlin/JS. This has a number of benefits: besides syntax, it also allows us to share our libraries and programming paradigms (such as using coroutines for concurrency), on both frontend and backend. |
30 | 43 |
|
31 |
| -Using Kotlin throughout the whole stack also makes it possible to write classes and functions that can be used from both the JVM and JS targets of our application. For this application, we will primarily use this functionality to share a typesafe representation of our data between client and server. |
| 44 | +Using Kotlin throughout the whole stack also makes it possible to write classes and functions that can be used from both the JVM and JS targets of our application. In this tutorial, we will primarily use this functionality to share a typesafe representation of our data between client and server. |
32 | 45 |
|
33 |
| -By delegating the task of serizaliation and deserialization from and to typesafe objects to multiplatform Kotlin libraries such as `kotlinx.serialization`, we can make the communication of data safe and practically trivial. |
| 46 | +By delegating the task of serialization and deserialization from and to typesafe objects to the `kotlinx.serialization` multiplatform library, we can make the communication of data safe and practically trivial. |
34 | 47 |
|
35 | 48 | Motivated enough? Let's dive in!
|
0 commit comments