Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple TODO application sample showing how to use kuick, ktor and kor…
…te (#31) * Simple TODO application sample showing how to use kuick, ktor and korte * Try to use a cache that already exists for the todo list (though probably not used since getting all) * More work * Some fixes * Small adjustment
- Loading branch information
Showing
30 changed files
with
527 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
kuick-core/src/commonMain/kotlin/kuick/repositories/annotations/annotations.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package kuick.utils | ||
|
||
import java.util.* | ||
|
||
fun randomUUID() = UUID.randomUUID().toString() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
dependencies { | ||
jvmApi project(":kuick-http") | ||
jvmMainApi "io.ktor:ktor-server-netty:$ktor_version" | ||
jvmMainApi "io.ktor:ktor-locations:$ktor_version" | ||
//jvmApi project(":kuick-db") | ||
jvmTestImplementation "io.ktor:ktor-server-test-host:$ktor_version" | ||
jvmTestImplementation project(":kuick-repositories-squash") | ||
} |
38 changes: 38 additions & 0 deletions
38
kuick-http-ktor/src/jvmMain/kotlin/kuick/ktor/KtorApplicationHttpServer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package kuick.ktor | ||
|
||
/* | ||
import io.ktor.application.* | ||
import io.ktor.http.* | ||
import io.ktor.request.* | ||
import io.ktor.response.* | ||
import io.ktor.routing.* | ||
import kotlinx.coroutines.io.* | ||
import kotlinx.io.core.* | ||
import kuick.http.* | ||
import kuick.http.HttpMethod | ||
class KtorApplicationHttpServer(val app: Application) : HttpServer { | ||
override suspend fun register(path: String, method: HttpMethod, handler: suspend (HttpRequest) -> HttpResponse) { | ||
app.routing { | ||
route(path, method.toKtor()) { | ||
handle { | ||
val response = handler(call.request.toKuick()) | ||
for ((key, value) in response.headers.headers) { | ||
call.response.header(key, value) | ||
} | ||
call.respond(HttpStatusCode.fromValue(response.statusCode), response.retrieveBody()) | ||
} | ||
} | ||
} | ||
} | ||
fun HttpMethod.toKtor() = io.ktor.http.HttpMethod.parse(this.name) | ||
fun io.ktor.http.HttpMethod.toKuick() = HttpMethod.parse(this.value) | ||
fun io.ktor.http.Headers.toKuick() = kuick.http.HttpHeaders(this.entries().flatMap { pair -> pair.value.map { pair.key to it } }) | ||
suspend fun ApplicationRequest.toKuick(): HttpRequest { | ||
return SimpleHttpRequest(this.path(), this.httpMethod.toKuick(), this.headers.toKuick(), this.receiveChannel().readRemaining().readBytes()) | ||
} | ||
} | ||
*/ |
13 changes: 13 additions & 0 deletions
13
kuick-http-ktor/src/jvmMain/kotlin/kuick/ktor/KtorContextPerConnection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package kuick.ktor | ||
|
||
import com.google.inject.* | ||
import io.ktor.application.* | ||
import kuick.di.* | ||
import kotlin.coroutines.* | ||
|
||
fun Application.installContextPerRequest(injector: Injector, context: CoroutineContext.Element, callback: suspend () -> Unit) { | ||
val perCoroutineJob = injector.get<PerCoroutineJob>() | ||
perCoroutineJob.registerContext(context) | ||
perCoroutineJob.runBlocking { callback() } | ||
install(PerCoroutineJobFeature(injector)) | ||
} |
Oops, something went wrong.