Skip to content
This repository was archived by the owner on May 17, 2023. It is now read-only.

Commit e16af5c

Browse files
Merge pull request #125 from andreyaksenov/update-links
add a link to a new plugin, fix help links
2 parents 395d434 + e34c4e0 commit e16af5c

File tree

10 files changed

+23
-23
lines changed

10 files changed

+23
-23
lines changed

Creating HTTP APIs with Ktor/02_application-init.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Project setup
22

3-
If we were to start a fresh idea from zero, Ktor would have a few ways of setting up a preconfigured Gradle project: [start.ktor.io](https://start.ktor.io/) and the [Ktor IntelliJ IDEA plugin](https://plugins.jetbrains.com/plugin/10823-ktor) make it easy to create a starting-off point for projects using a variety of features from the framework.
3+
If we were to start a fresh idea from zero, Ktor would have a few ways of setting up a preconfigured Gradle project: [start.ktor.io](https://start.ktor.io/) and the [Ktor IntelliJ IDEA plugin](https://plugins.jetbrains.com/plugin/16008-ktor) make it easy to create a starting-off point for projects using a variety of features from the framework.
44

55
For this tutorial, however, we have made a starter template available that includes all configuration and required dependencies for the project.
66

@@ -35,9 +35,9 @@ Let's briefly go through these dependencies one-by-one:
3535

3636
### Configurations: `application.conf` and `logback.xml`
3737

38-
The repository also includes a basic `application.conf` in [HOCON](https://en.wikipedia.org/wiki/HOCON) format, located in the `resources` folder. Ktor uses this file to determine the port on which it should run, and it also defines the entry point of our application. If you'd like to learn more about how a Ktor server is configured, check out the [official documentation](https://ktor.io/servers/configuration.html).
38+
The repository also includes a basic `application.conf` in [HOCON](https://en.wikipedia.org/wiki/HOCON) format, located in the `resources` folder. Ktor uses this file to determine the port on which it should run, and it also defines the entry point of our application. If you'd like to learn more about how a Ktor server is configured, check out the [official documentation](https://ktor.io/docs/configurations.html).
3939

40-
Also included in the same folder is a `logback.xml` file, which sets up the basic logging structure for our server. If you'd like to learn more about logging in Ktor, check out the [official documentation](https://ktor.io/servers/logging.html).
40+
Also included in the same folder is a `logback.xml` file, which sets up the basic logging structure for our server. If you'd like to learn more about logging in Ktor, check out the [official documentation](https://ktor.io/docs/logging.html).
4141

4242
### Entry point
4343

Creating HTTP APIs with Ktor/03_customer-routes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ get {
7272
}
7373
```
7474

75-
In order for this to work, we need to enable [content negotiation](https://ktor.io/servers/features/content-negotiation.html) in Ktor. What does content negotiation do? Let us consider the following request:
75+
In order for this to work, we need to enable [content negotiation](https://ktor.io/docs/serialization.html) in Ktor. What does content negotiation do? Let us consider the following request:
7676

7777
```http request
7878
GET http://0.0.0.0:8080/customer
@@ -102,7 +102,7 @@ GET http://0.0.0.0:8080/customer/200
102102
Accept: application/json
103103
```
104104

105-
In Ktor, paths can also contain [parameters](https://ktor.io/servers/features/routing.html#parameters) that match specific path segments. We can access their value using the indexed access operator (`call.parameters["myParamName"]`). Let's add the following code to the `get("{id}")` entry:
105+
In Ktor, paths can also contain [parameters](https://ktor.io/docs/routing-in-ktor.html#match_url) that match specific path segments. We can access their value using the indexed access operator (`call.parameters["myParamName"]`). Let's add the following code to the `get("{id}")` entry:
106106

107107

108108
```kotlin

Creating HTTP APIs with Ktor/07_Whats_Next.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ features such as Authentication, etc.
55

66
### Feature requests
77

8-
- **Authentication**: currently, the API is open to whomever would like to access it. If you want to restrict access, have a look at Ktor's support for [JWT](https://ktor.io/servers/features/authentication/jwt.html) and other authentication methods.
8+
- **Authentication**: currently, the API is open to whomever would like to access it. If you want to restrict access, have a look at Ktor's support for [JWT](https://ktor.io/docs/jwt.html) and other authentication methods.
99

1010
- **Learn more about route organization!** If you'd like to learn about different ways to organize your routes with Ktor, check out [this article](https://hadihariri.com/2020/04/02/Routing-in-Ktor/) by Hadi Hariri.
1111

Creating a WebSocket Chat with Ktor/02_Project_Setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Project setup
22

3-
Because our application will be two independent parts (chat server and chat client) we structure our application as two separate Gradle projects. Since these two projects are completely independent, they could be created manually, via the online [Ktor Project Generator](https://start.ktor.io/#), or the [plugin for IntelliJ IDEA](https://plugins.jetbrains.com/plugin/10823-ktor).
3+
Because our application will be two independent parts (chat server and chat client) we structure our application as two separate Gradle projects. Since these two projects are completely independent, they could be created manually, via the online [Ktor Project Generator](https://start.ktor.io/#), or the [plugin for IntelliJ IDEA](https://plugins.jetbrains.com/plugin/16008-ktor).
44

55
To skip over these configuration steps, a starter template is available for this specific tutorial, which includes all configuration and required dependencies for our two projects already.
66

Creating a website with Ktor/02_Project_setup.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Project Setup
22

3-
If we were to start a fresh idea from zero, Ktor would have a few ways of setting up a preconfigured Gradle project: [start.ktor.io](https://start.ktor.io/) and the [Ktor IntelliJ IDEA plugin](https://plugins.jetbrains.com/plugin/10823-ktor) make it easy to create a starting-off point for projects using a variety of features from the framework.
3+
If we were to start a fresh idea from zero, Ktor would have a few ways of setting up a preconfigured Gradle project: [start.ktor.io](https://start.ktor.io/) and the [Ktor IntelliJ IDEA plugin](https://plugins.jetbrains.com/plugin/16008-ktor) make it easy to create a starting-off point for projects using a variety of features from the framework.
44

55
For this tutorial, however, we have made a starter template available that includes all configuration and required dependencies for the project.
66

@@ -33,8 +33,8 @@ Let's briefly go through these dependencies one-by-one:
3333

3434
### Configurations: `application.conf` and `logback.xml`
3535

36-
The repository also includes a basic `application.conf` in HOCON format. Ktor uses this file to determine the port on which it should run, and it also defines the entry point of our application to be `com.jetbrains.handson.website.ApplicationKt.module`. This corresponds to the `Application.module()` function in `Application.kt`, which we'll start modifying in the next section. If you'd like to learn more about how a Ktor server is configured, check out the [official documentation](https://ktor.io/servers/configuration.html).
36+
The repository also includes a basic `application.conf` in HOCON format. Ktor uses this file to determine the port on which it should run, and it also defines the entry point of our application to be `com.jetbrains.handson.website.ApplicationKt.module`. This corresponds to the `Application.module()` function in `Application.kt`, which we'll start modifying in the next section. If you'd like to learn more about how a Ktor server is configured, check out the [official documentation](https://ktor.io/docs/configurations.html).
3737

38-
Also included is a `logback.xml` in the `resources` folder, which sets up the basic logging structure for our server. If you'd like to learn more about logging in Ktor, check out the [official documentation](https://ktor.io/servers/logging.html).
38+
Also included is a `logback.xml` in the `resources` folder, which sets up the basic logging structure for our server. If you'd like to learn more about logging in Ktor, check out the [official documentation](https://ktor.io/docs/logging.html).
3939

4040
Now that we are equipped with some knowledge around all the artifacts we have at our fingertips, we can start by actually writing the first part of our journal app!

Creating a website with Ktor/03_static_assets.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ In the context of our journal, there are a number of things that we probably wan
66

77
![](./assets/ktor_image_location.png)
88

9-
For serving static content, we can use a specific [`routing`](https://ktor.io/servers/features/routing.html) function already built in to Ktor named `static`. The function takes two parameters: the route under which the static content should be made available, and a lambda where we can define the location from where the content should be served. In the file called `Application.kt`, let's change the implementation for `Application.module()` to look like this:
9+
For serving static content, we can use a specific [`routing`](https://ktor.io/docs/routing-in-ktor.html) function already built in to Ktor named `static`. The function takes two parameters: the route under which the static content should be made available, and a lambda where we can define the location from where the content should be served. In the file called `Application.kt`, let's change the implementation for `Application.module()` to look like this:
1010

1111
```kotlin
1212
fun Application.module() {
@@ -58,6 +58,6 @@ If we re-run the application and navigate to [`http://localhost:8080/static/abou
5858

5959
Of course, we could also organize our files in subdirectories inside `files`; Ktor will automatically take care of mapping these paths to the correct URLs.
6060

61-
If you'd like to learn more about serving static files with Ktor, check out the [official documentation](https://ktor.io/servers/features/static-content.html).
61+
If you'd like to learn more about serving static files with Ktor, check out the [official documentation](https://ktor.io/docs/serving-static-content.html).
6262

6363
However, a static page that contains a few paragraphs can hardly be called a journal yet. Let's move on and learn about how *templates* can help us in writing pages that contain dynamic content, and how to control them from within our application.

Creating a website with Ktor/04_homepage_with_freemarker.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Home page with templates
22

3-
It's time to build the main page of our journal which is in charge of displaying multiple journal entries. We will create this page with the help of a *template engine*. Template engines are quite common in web development, and Ktor supports a [variety of them](https://ktor.io/servers/features/templates.html). In our case we're going to choose [FreeMarker](https://freemarker.apache.org/).
3+
It's time to build the main page of our journal which is in charge of displaying multiple journal entries. We will create this page with the help of a *template engine*. Template engines are quite common in web development, and Ktor supports a [variety of them](https://ktor.io/docs/working-with-views.html). In our case we're going to choose [FreeMarker](https://freemarker.apache.org/).
44

55
### Adding FreeMarker as a Ktor feature
66

7-
[Features](https://ktor.io/servers/features.html) are a mechanism that Ktor provides to enable support for certain functionality, such as encoding, compression, logging, authentication, among others. While the implementation details of Ktor features (acting as interceptors / middleware providing extra functionality) aren't relevant for this hands-on tutorial, we will use this mechanism to `install` the `FreeMarker` feature, by adding the following lines to the top of our `Application.module()` definition in the `Application.kt` file:
7+
[Features](https://ktor.io/docs/features.html) are a mechanism that Ktor provides to enable support for certain functionality, such as encoding, compression, logging, authentication, among others. While the implementation details of Ktor features (acting as interceptors / middleware providing extra functionality) aren't relevant for this hands-on tutorial, we will use this mechanism to `install` the `FreeMarker` feature, by adding the following lines to the top of our `Application.module()` definition in the `Application.kt` file:
88

99
```kotlin
1010
fun Application.module() {

Creating a website with Ktor/05_Submitting_new_entries.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ post("/submit") {
1313
}
1414
```
1515

16-
[`receiveParameters`](https://ktor.io/servers/calls/requests.html#post) allows us to parse form data (for both `urlencoded` and `multipart`). We then extract the `headline` and `body` fields from the form, ensuring they are both not null, and create a new `BlogEntry` object from this information, adding it to the beginning of our `blogEntries` list.
16+
[`receiveParameters`](https://ktor.io/docs/requests.html#post-put-and-patch) allows us to parse form data (for both `urlencoded` and `multipart`). We then extract the `headline` and `body` fields from the form, ensuring they are both not null, and create a new `BlogEntry` object from this information, adding it to the beginning of our `blogEntries` list.
1717

18-
For more detailed information on the fancy features that are available in the context of Ktor's request model, check out the [official documentation](https://ktor.io/servers/calls/requests.html).
18+
For more detailed information on the fancy features that are available in the context of Ktor's request model, check out the [official documentation](https://ktor.io/docs/requests.html).
1919

2020
To show the user that the submission was successful, we still want to send back a bit of HTML. We could re-use our knowledge and create a FreeMarker template for this "Success" page as well – but to cover some more Ktor functionality, we will try an alternative approach instead. When we autocomplete on the `call` object, we can see that Ktor allows us to respond to requests using a variety of functions:
2121

Creating a website with Ktor/06_Whats_Next.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ At this point, you should have gotten a basic idea of how to serve static files
77
At this point, our journal application is still rather barebones, so of course it might be a fun challenge to add more features to the project, and learn even more about building interactive sites with Kotlin and Ktor. To get you started, here's a few ideas of how the application could still be improved, in no particular order:
88

99
- **Make it consistent!** You would usually not mix FreeMarker and kotlinx.html – we've taken some liberty here to explore more than one way of structuring your application. Consider powering your whole journal with kotlinx.html or FreeMarker, and make it consistent!
10-
- **Authentication!** Our current version of the journal allows all visitors to post content to our journal. We could use [Ktor's authentication features](https://ktor.io/servers/features/authentication.html) to ensure that only select users can post to the journal, while keeping read access open to everyone.
10+
- **Authentication!** Our current version of the journal allows all visitors to post content to our journal. We could use [Ktor's authentication features](https://ktor.io/docs/authentication.html) to ensure that only select users can post to the journal, while keeping read access open to everyone.
1111
- **Persistence!** Currently, all our journal entries vanish when we stop our application, as we are only storing them in a variable. You could try integrating your application with a database like PostgreSQL or MongoDB, using one of the plenty projects that allow database access from Kotlin, like [Exposed](https://github.com/JetBrains/Exposed) or [KMongo](https://litote.org/kmongo/).
1212
- **Make it look nicer!** The stylesheets for the journal are currently rudimentary at best. Consider creating your own style sheet, and serving it as a static `.css` file from Ktor!
1313
- **Organize your routes!** As the complexity of our application increases, so does the number of routes we try to support. For bigger applications, we usually want to add structure to our routing – like separating routes out into separate files. If you'd like to learn about different ways to organize your routes with Ktor, check out [this article](https://hadihariri.com/2020/04/02/Routing-in-Ktor/) by Hadi Hariri.

0 commit comments

Comments
 (0)