Benjamin Schlie
02/05/2021, 4:08 PMinstall(StatusPages)
in each of them. The routes works, but not the StatusPages.
routing {
header(HttpHeaders.Host, "localhost:8080") {
route("/") {
handle {
call.respondText("Hello world")
}
}
install(StatusPages) {
status(HttpStatusCode.NotFound) { status ->
call.respondText("Not found!")
}
}
}
}
routing {
header(HttpHeaders.Host, "another-host:8080") {
route("/") {
handle {
call.respondText("Hello another world")
}
}
install(StatusPages) {
status(HttpStatusCode.NotFound) { status ->
call.respondText("No other world found!")
}
}
}
}
rsetkus
02/08/2021, 1:31 AMPUT
request, api returns an empty body response but all types of ktor requests have a return type. To satisfy it, have created an empty data class, however getting an error when executing such request:
io.ktor.client.call.NoTransformationFoundException: No transformation found: class <http://io.ktor.utils.io|io.ktor.utils.io>.ByteBufferChannel (Kotlin reflection is not available) -> class xx.yy.api.NoContent (Kotlin reflection is not available)
.
I’d guess serialization process is confused when mapping an empty response to data class. Any ideas how to fix it?why
02/08/2021, 10:34 AMClientRequestException
in my unit tests? is it possible?
I’m using the MockEngine like this
val httpClientMock = HttpClient(MockEngine) {
HttpResponseValidator { }
install(JsonFeature) {
serializer = GsonSerializer()
}
engine {
addHandler { request ->
val page = request.url.parameters["page"]!!.toInt()
when {
page < 38 -> {
val t = ContentType.Application.Json.toString()
val headers = headersOf("Content-Type" to listOf(t))
TextContent(reposJson, ContentType.Application.Json)
respond(reposJson, headers = headers)
}
else -> throw "I can't ctor the exception"
}
}
}
}
KamilH
02/09/2021, 4:36 PMjava.lang.NoClassDefFoundError: Failed resolution of: Lio/ktor/client/features/json/JsonFeature;
exception, even though I can see that library’s pom file contains all of the required dependencies and my consuming app is downloading those dependencies. Library is working well in the Kotlin project. Do I need to add some kind of a configuration to be able to use it from Java app?Marc de Palol
02/09/2021, 10:02 PMEngine doesn’t support io.ktor.client.features.HttpTimeout$Feature@5c8a5ca9
, if I don’t install it I get another error: Consider installing io.ktor.client.features.HttpTimeout$Feature@157a2816 feature because the request requires it to be installed
Isn’t there any workaround?Jawid
02/10/2021, 3:50 PMpambrose
02/10/2021, 6:05 PM<section data-markdown> ... </section>
would be? In other words, how are tag attributes with no values expressed in the DSL?Hexa
02/11/2021, 9:26 AMMarc Knaup
02/11/2021, 5:14 PMAmritansh
02/11/2021, 6:47 PMJeff Tycz
02/12/2021, 1:45 AMsuspend inline fun <reified T> post(authKey: String, url: String, data: Any): T? {
val response = <http://_client.post|_client.post><HttpResponse>(url) {
header("Authorization", "Bearer $authKey")
contentType(ContentType.Application.Json)
body = data
}
when (response.status.value) {
in 300..399 -> throw RedirectResponseException(response)
in 400..499 -> throw ClientRequestException(response)
in 500..599 -> throw ServerResponseException(response)
}
if (response.status.value >= 600) {
throw ResponseException(response)
}
return response.receive<T>()
}
Is there a way to dynamically set the headers?Paul Woitaschek
02/13/2021, 11:40 AM@Test
fun test() {
val client = HttpClient()
runBlocking {
println("start")
val result: String = client.get("<https://www.google.com/>")
println("result=$result")
}
}
I’m using
implementation("io.ktor:ktor-client-ios:1.5.1")
And
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2-native-mt
With the strictly
block appliednatario1
02/14/2021, 1:12 PMalexfu
02/14/2021, 1:39 PMException doesn't match @Throws-specified class list and thus isn't propagated from Kotlin to Objective-C/Swift as NSError
I've determined this happens because, in Kotlin, it's not required to specify if a function throws an exception. However, when targeting a native platform, if you don't specify that the function throws, those errors will be uncaught. So what I'm doing to resolve this is to add @Throws(Throwable::class)
to every single API function I have. I'm wondering if there is an easier way to manage this since there's no lint type check for this (that I'm aware of), making it's easy to forget. I also feel like this may be more of a Kotlin question than a Ktor one.iona bartishvili
02/14/2021, 6:58 PMJoão Eudes Lima
02/15/2021, 1:36 AMNikolay Kasyanov
02/15/2021, 8:23 AMptsiogas
02/15/2021, 5:25 PMCLOVIS
02/15/2021, 7:28 PMsmallufo
02/15/2021, 7:37 PMktor-client-serialization
(1.5.1) to kotlinx-serialization-json
dependency ?
I tried
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-client-serialization</artifactId>
<version>${ktor_version}</version>
</dependency>
but IntelliJ & maven always complains Cannot resolve org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1
command line mvn complains :
Caused by: org.eclipse.aether.resolution.DependencyResolutionException: Could not find artifact org.jetbrains.kotlinx:kotlinx-serialization-json:jar:1.0.1 in central (<https://repo.maven.apache.org/maven2>)
at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies (DefaultRepositorySystem.java:352)
at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve (DefaultProjectDependenciesResolver.java:202)
And in maven center
https://repo.maven.apache.org/maven2/org/jetbrains/kotlinx/kotlinx-serialization-json/1.0.1/
There is no jar file . That’s why maven complains it cannot find JAR file.
KSJ is packaging in POM , not JAR
https://repo.maven.apache.org/maven2/org/jetbrains/kotlinx/kotlinx-serialization-json/1.0.1/kotlinx-serialization-json-1.0.1.pom
<packaging>pom</packaging>
Is it OK to import it like this ? https://repo1.maven.org/maven2/io/ktor/ktor-client-serialization/1.5.1/ktor-client-serialization-1.5.1.pom
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-serialization-json</artifactId>
<version>1.0.1</version>
<scope>compile</scope>
</dependency>
Sorry not sure about this. but it seems not working.
Is it maven center’s problem ?Anders Sveen
02/16/2021, 10:22 AMJawid
02/16/2021, 1:54 PMclient.submitFormWithBinaryData<FaceResponse> {
method = <http://HttpMethod.Post|HttpMethod.Post>
url(IMAGE_URL)
headers {
this["x-api-key"] = "my_api_key_here"
}
parameter(
"mode", "request_mode"
)
body = MultiPartFormDataContent(formData {
append("image", request.image)
})
}
Does anyone know what is the issue? Thanksrsetkus
02/16/2021, 2:19 PMSatyam Agarwal
02/16/2021, 3:10 PMPaul Woitaschek
02/17/2021, 9:56 AMPaul Griffith
02/17/2021, 6:51 PMXClient
which might be backed by a CIOEngine
...but also be able to use the same class but with a MockEngine
, which requires being able to add handlersAnders Sveen
02/18/2021, 1:52 PMContinuationInterceptor
to KTor Server execution context? I am trying to add one just by doing GlobalScope.embeddedServer(factory = Jetty, ... , parentCoroutineContext = MyContinuationInterceptor())
, but the interceptor never seems to trigger. I have done something similar with an Interceptor and withContext(MyContinuationInterceptor()) { ... }
. That works, but thought I would "plug it in" at the "top" to see if I could do that. Is it at all possible?Daniele B
02/18/2021, 3:17 PMSLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See <http://www.slf4j.org/codes.html#StaticLoggerBinder> for further details.
is it normal?olfek
02/18/2021, 7:15 PMvar myVariable : String? = null
fun main(args: Array<String>): Unit {
myVariable = "Hello World"
io.ktor.server.netty.EngineMain.main(args)
}
@Suppress("unused") // Referenced in application.conf
@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
// myVariable is null here
}
napperley
02/18/2021, 11:46 PMnapperley
02/18/2021, 11:46 PM