Skip to content

Commit b09fc2c

Browse files
authored
KTOR-8962 Update the Create a new Ktor project tutorial (#708)
* KTOR-8962 Update the Create a new Ktor project tutorial * fix wrong library name * update code snippets * update the example explanation in maven-assembly-plugin.md * KTOR-9002 update maven dependency and add a warning for YAML support * update screenshots and fix casing * fix final step in second additional task
1 parent 83e2bd8 commit b09fc2c

File tree

47 files changed

+844
-495
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+844
-495
lines changed

codeSnippets/settings.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ module("snippets", "deployment-ktor-plugin")
120120
module("snippets", "tutorial-website-static")
121121
module("snippets", "server-websockets-sharedflow")
122122
module("snippets", "tutorial-client-get-started")
123-
module("snippets", "tutorial-server-get-started")
124123
module("snippets", "tutorial-server-web-application")
125124
module("snippets", "server-websockets-serialization")
126125
module("snippets", "client-websockets-serialization")

codeSnippets/snippets/tutorial-server-get-started-maven/pom.xml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
<name>tutorial-server-get-started-maven</name>
99
<description>tutorial-server-get-started-maven</description>
1010
<properties>
11-
<ktor_version>3.3.1</ktor_version>
1211
<kotlin.code.style>official</kotlin.code.style>
1312
<kotlin_version>2.2.20</kotlin_version>
14-
<logback_version>1.5.18</logback_version>
15-
<slf4j_version>2.0.12</slf4j_version>
13+
<ktor_version>3.3.1</ktor_version>
14+
<logback_version>1.4.14</logback_version>
15+
<slf4j_version>2.0.9</slf4j_version>
1616
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1717
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
18-
<main.class>com.example.ApplicationKt</main.class>
18+
<main.class>io.ktor.server.netty.EngineMain</main.class>
1919
</properties>
2020
<repositories>
2121
</repositories>
@@ -35,6 +35,11 @@
3535
<artifactId>logback-classic</artifactId>
3636
<version>${logback_version}</version>
3737
</dependency>
38+
<dependency>
39+
<groupId>io.ktor</groupId>
40+
<artifactId>ktor-server-status-pages-jvm</artifactId>
41+
<version>${ktor_version}</version>
42+
</dependency>
3843
<dependency>
3944
<groupId>org.slf4j</groupId>
4045
<artifactId>slf4j-api</artifactId>
@@ -111,7 +116,7 @@
111116
<plugin>
112117
<groupId>org.apache.maven.plugins</groupId>
113118
<artifactId>maven-assembly-plugin</artifactId>
114-
<version>2.6</version>
119+
<version>3.7.1</version>
115120
<configuration>
116121
<descriptorRefs>
117122
<descriptorRef>jar-with-dependencies</descriptorRef>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.example
2+
3+
import io.ktor.server.application.*
4+
5+
fun main(args: Array<String>) {
6+
io.ktor.server.netty.EngineMain.main(args)
7+
}
8+
9+
fun Application.module() {
10+
configureRouting()
11+
}
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
package com.example.plugins
1+
package com.example
22

3-
import io.ktor.http.*
3+
import io.ktor.http.ContentType
44
import io.ktor.server.application.*
5-
import io.ktor.server.http.content.*
5+
import io.ktor.server.http.content.staticResources
6+
import io.ktor.server.plugins.statuspages.StatusPages
67
import io.ktor.server.response.*
78
import io.ktor.server.routing.*
8-
import io.ktor.server.routing.get
9-
import io.ktor.server.plugins.statuspages.*
109

1110
fun Application.configureRouting() {
1211
install(StatusPages) {
@@ -21,11 +20,14 @@ fun Application.configureRouting() {
2120
call.respondText("Hello World!")
2221
}
2322

23+
// ...
24+
2425
get("/test1") {
2526
val text = "<h1>Hello From Ktor</h1>"
2627
val type = ContentType.parse("text/html")
2728
call.respondText(text, type)
2829
}
30+
2931
get("/error-test") {
3032
throw IllegalStateException("Too Busy")
3133
}

codeSnippets/snippets/tutorial-server-get-started-maven/src/main/kotlin/com/example/Application.kt

Lines changed: 0 additions & 15 deletions
This file was deleted.

codeSnippets/snippets/tutorial-server-get-started-maven/src/main/kotlin/com/example/plugins/Routing.kt

Lines changed: 0 additions & 13 deletions
This file was deleted.

codeSnippets/snippets/tutorial-server-get-started-maven/src/main/resources/logback.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
55
</encoder>
66
</appender>
7-
<root level="trace">
7+
<root level="INFO">
88
<appender-ref ref="STDOUT"/>
99
</root>
1010
<logger name="org.eclipse.jetty" level="INFO"/>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.example
2+
3+
import io.ktor.client.request.get
4+
import io.ktor.client.statement.bodyAsText
5+
import io.ktor.http.HttpStatusCode
6+
import io.ktor.http.contentType
7+
import io.ktor.server.testing.testApplication
8+
import kotlin.test.Test
9+
import kotlin.test.assertContains
10+
import kotlin.test.assertEquals
11+
12+
class ApplicationTest {
13+
14+
@Test
15+
fun testRoot() = testApplication {
16+
application {
17+
module()
18+
}
19+
val response = client.get("/")
20+
21+
assertEquals(HttpStatusCode.OK, response.status)
22+
assertEquals("Hello World!", response.bodyAsText())
23+
}
24+
25+
@Test
26+
fun testNewEndpoint() = testApplication {
27+
application {
28+
module()
29+
}
30+
31+
val response = client.get("/test1")
32+
33+
assertEquals(HttpStatusCode.OK, response.status)
34+
assertEquals("html", response.contentType()?.contentSubtype)
35+
assertContains(response.bodyAsText(), "Hello From Ktor")
36+
}
37+
}

codeSnippets/snippets/tutorial-server-get-started-maven/src/test/kotlin/com/example/ApplicationTest.kt

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)