forked from ktorio/ktor-documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_Ktor_Application.xml
102 lines (97 loc) · 4.51 KB
/
A_Ktor_Application.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic SYSTEM "https://resources.jetbrains.com/stardust/html-entities.dtd">
<topic xmlns="" xsi:noNamespaceSchemaLocation="https://resources.jetbrains.com/stardust/topic.v2.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="A_Ktor_Application" title="A Ktor application">
<p>Ktor can be used to create a variety of server and <a href="create-client.md">client-side</a> applications.
Whether we want to create a website that serves static and dynamic pages, an HTTP endpoint, a RESTful system, or
even microservices, Ktor makes it all possible.
</p>
<p>In this section, we're going to cover the basics of what a Ktor Server Application is and how the pieces all fit
together.
</p>
<chapter id="hello-world" title="The simplest Ktor application">
<p>One of Ktor's goals is to remain as simple as possible and to avoid any kind of <i>magic</i>. The equivalent
to a <i>Hello World</i> application in Ktor would be:
</p>
<code style="block"
lang="kotlin"
src="snippets/embedded-server/src/main/kotlin/com/example/Application.kt"
include-symbol="main">
</code>
<p>
We start by <a href="create_server.xml">creating a server</a>, in this case using Netty as an <a href="Engines.md">Engine</a>, and setting the port to 8080. After this, we define a route to respond to requests made to <path>/</path> with a simple <emphasis>Hello, world!</emphasis> text. Finally, we start the server.
</p>
</chapter>
<chapter title="Next steps" id="next">
<p>
In the next chapters, we'll take a look at the main concepts of creating a Ktor application -
from configuring a server to using plugins, which is core to all Ktor applications:
</p>
<list>
<li>
<p>
<a href="server-dependencies.xml">Add Ktor dependencies</a>
</p>
<p>
Learn how to add dependencies required for a Ktor server to a Gradle or Maven project.
</p>
</li>
<li>
<p>
<a href="create_server.xml">Choose a way to create a server</a>
</p>
<p>
You can quickly configure a server using the <code>embeddedServer</code> function, or you can use <code>EngineMain</code> to have additional configuration possibilities.
</p>
</li>
<li>
<p>
<a href="Engines.md">Choose an engine</a>
</p>
<p>
Configuring a server requires choosing an engine, such as Netty, Jetty, Tomcat, and so on.
</p>
</li>
<li>
<p>
<a href="Configurations.xml">Configure a server</a>
</p>
<p>
Learn how to configure various server parameters (such as a host address and port, modules to load, etc.), read the configuration in code, and use environment variables.
</p>
</li>
<li>
<p>
<a href="Plugins.md">Add functionality with Plugins</a>
</p>
<p>
Get acquainted with plugins that provide common functionality, for example, serialization and content encoding, compression, headers, cookie support, etc.
</p>
</li>
<li>
<p>
<a href="Routing_in_Ktor.md">Handle requests with Routing</a>
</p>
<p>
Learn how to handle incoming requests made to different URLs using routing.
</p>
</li>
<li>
<p>
<a href="Modules.md">Divide your application into Modules</a>
</p>
<p>
Use modules to divide your application into logical parts, each of which can house any functionality.
</p>
</li>
<li>
<p>
<a href="Structuring_Applications.md">Structure your application</a>
</p>
<p>
Learn how to structure your application to keep it maintainable as the application grows.
</p>
</li>
</list>
</chapter>
</topic>