Skip to content

Latest commit

 

History

History
 
 

codeSnippets

Ktor code examples

The codeSnippets folder of a Ktor documentation repository contains a Gradle project with runnable code examples that show how to work with various Ktor plugins. Code from these examples is referenced in corresponding documentation sections.

You can run any of these examples in IntelliJ IDEA in the following way:

  1. Clone a Ktor documentation repository.

  2. Open the codeSnippets folder and wait until IntelliJ IDEA imports a Gradle project with code examples. You can see all the examples in a Project view by expanding the snippets folder.

    Code snippets

    Each example has its own README file with instructions on how to run it.

  3. To run an example, you can use a run Gradle task that depends on an example location. For example, to run an example demonstrating basic HTTP authentication (the snippets/auth-basic folder), open the codeSnippets folder in a terminal and execute the following command:

    ./gradlew :auth-basic:run

    Wait until IntelliJ IDEA builds and runs an example.

    Run example in a terminal

Referencing code snippets

To display a specific source file in a Markdown topic, use the src attribute as follows:

```kotlin
```
{src="snippets/autohead/src/main/kotlin/com/example/Application.kt"}

If you want to display only a specific function from this source file, use the include-symbol attribute:

```kotlin
```
{src="snippets/autohead/src/main/kotlin/com/example/Application.kt" include-symbol="main"}