-
Notifications
You must be signed in to change notification settings - Fork 0
Add initial starters for Ktor server #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
(cherry picked from commit 413d935ca199216a3885df36fe1f5f48dac9329b)
(cherry picked from commit 69c025dafbb59a3f91e1ca3eadd382b6bf74df22)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea to have starters! I have some comments
// installExposed( | ||
// JdbcConfiguration( | ||
// url = "jdbc:postgresql://localhost:5432/ktor-sample", | ||
// username = "ktor-sample", | ||
// password = "ktor-sample" | ||
// ) | ||
// ) { | ||
// createSchema(UserEntity) | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a description why this code is commented out?
plugins { | ||
id("ktor-sample.kotlin-jvm") | ||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit
plugins { | |
id("ktor-sample.kotlin-jvm") | |
} | |
plugins { | |
id("ktor-sample.kotlin-jvm") | |
} |
dependencies { | ||
api(libs.ktor.server.core) | ||
api(libs.ktor.serialization.kotlinx.json) | ||
api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to the version catalog?
@@ -0,0 +1,17 @@ | |||
plugins { | |||
id("ktor-sample.kotlin-jvm") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a bit weird that this module is called starter-ktor-web
, but it is a JVM module. Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not so sure about the structure of this project - users won't be able to download a folder and run it as a standalone project, and introducing more starters would require some structural changes. It may be better to just introduce samples like this as plugins in the registry now that we have multi-module layouts, though it depends on how complex you want to make it.
dependencies { | ||
api(libs.ktor.server.core) | ||
api(libs.ktor.serialization.kotlinx.json) | ||
api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a duplicate here.
class CrudRepository<E : CrudTable<E, M>, M>( | ||
private val table: CrudTable<E, M> | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to introduce an interface so we don't overexpose Exposed and can introduce new abstractions. There's also a small problem with only allowing integer ID's here.
My implementation in the chat app covers some of this:
Class: ExposedRepository.kt
Implementation: Repository.kt
I also used Database as a dependency so you can have more flexibility in your connections. I noticed the current implementation here requires static configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you help me updating this starter with structure from the chat application? So we can use a starter for the chat sample
fun Application.installExposed( | ||
databaseConfiguration: DatabaseConfiguration, | ||
exposedConfiguration: ExposedConfiguration.() -> Unit | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like how it's mixing Application and static scopes here. We ought to be using an application attribute here for the database instance.
subprojects/starter-ktor-web/src/main/kotlin/io/ktor/starter/web/KtorStarterWeb.kt
Outdated
Show resolved
Hide resolved
import io.ktor.server.routing.* | ||
import io.ktor.starter.exposed.* | ||
|
||
fun Application.configureRoutes() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to include some rudimentary authentication in the sample application, with some admin user seeded in the newly created table. Maybe a protected todo list endpoint as well to show some code re-use.
No description provided.