Questions tagged [ktor]

Ktor is a Kotlin Web framework developed by JetBrains

Ktor (https://ktor.io/) is a Kotlin Web framework developed by JetBrains

1101 questions
44
votes
2 answers

Kotlinx Serialization MissingFieldException

I am in the process of converting from Moshi to kotlinx serialization with Ktor and when I try to make a request to get data I am getting this error kotlinx.serialization.MissingFieldException: Field 'attachments' is required, but it was…
tyczj
  • 71,600
  • 54
  • 194
  • 296
34
votes
7 answers

How to set '-Xuse-experimental=kotlin.experimental' in IntelliJ

while trying to build a Kotlin/Ktor application in IntelliJ, multiple warnings of the form Warning:(276, 6) Kotlin: This class can only be used with the compiler argument '-Xuse-experimental=kotlin.Experimental' are output. The warnings refer…
27
votes
3 answers

Serializer for class '...' is not found. Mark the class as @Serializable or provide the serializer explicitly

Hi I have a problem with serialization of class in kotlin build.gradl.kt ... plugins { application kotlin("jvm") version "1.6.21" kotlin("plugin.serialization").version("1.6.21") } ... depenedancies{ ... …
Victor Orlyk
  • 1,454
  • 2
  • 15
  • 27
22
votes
1 answer

java.lang.UnsupportedOperationException: Reflective setAccessible(true) disabled

When I run my Ktor application with gradle run then I've got the following exception: 19:21:11.795 [main] DEBUG io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework 19:21:11.810 [main] DEBUG…
softshipper
  • 32,463
  • 51
  • 192
  • 400
19
votes
3 answers

withTimeout function gives IllegalStateException: There is no event loop. Use runBlocking { ... } to start one. in Kotlin Multiplatform iOS client

Update: It works if I first execute a coroutine without timeout and then withTimeout. But If I execute a coroutine withTimeout first then it gives me an error. same goes for Async as well. I am creating a demo kotlin multiplatform application where…
Paresh Dudhat
  • 1,166
  • 1
  • 14
  • 28
18
votes
10 answers

ktor with kotlinx serialization: how to use JSON.nonstrict

I'm trying to initialize Ktor http client and setup json serialization. I need to allow non-strict deserialization which JSON.nonstrict object allows. Just can't get how to apply this setting to serializer. val client = HttpClient { …
Rodion Altshuler
  • 1,713
  • 1
  • 15
  • 31
17
votes
3 answers

Handling Exception in HttpClient Ktor

I have written a common code in a common module as below and tested in JS environment val response = client.post(url) { body = TextContent("""{"a":1,"b":2}""", ContentType.Application.Json) } if (response.status !=…
andylamax
  • 1,858
  • 1
  • 14
  • 31
16
votes
1 answer

How to Implement Custom Cache Mechanism with Kotlin Multiplatform(Android, iOS) Ktor Client

I am working on Kotlin Multiplatform Project. I used Ktor Client for Network calls. I want to cache some request based on some custom logic not based on response header. HttpCache feature provided by Ktor is Response Header driven and I am not able…
Randheer
  • 984
  • 6
  • 24
16
votes
6 answers

How to log requests in ktor http client?

I got something like this: private val client = HttpClient { install(JsonFeature) { serializer = GsonSerializer() } install(ExpectSuccess) } and make request like private fun HttpRequestBuilder.apiUrl(path: String, userId:…
Seko
  • 670
  • 1
  • 9
  • 19
15
votes
3 answers

Send application/x-www-form-urlencoded in Ktor

I can't figure out how to send a application/x-www-form-urlencoded POST request in Ktor. I see some submitForm helpers in Ktor's documentation but they don't send the request as expected. What I want is to replicate this curl line behavior: curl -d…
Martín Coll
  • 3,368
  • 3
  • 37
  • 52
14
votes
3 answers

How to inject dependencies in a ktor Application

The documentation talks about dependency injection but does not really show how it is being done. Documentation is not completed as well and has a bunch of place holders: http://ktor.io/getting-started.html I tried to create my main function in a…
Mehdi Karamosly
  • 5,388
  • 2
  • 32
  • 50
12
votes
9 answers

"No transformation found: class io.ktor.utils.io.ByteChannelNative" error using Ktor

I'm trying to fetch and deserialize some data that is being hosted on github. { "Meals": [ { "id": "1598044e-5259-11e9-8647-d663bd870b02", "name": "Tomato pasta", "quantity": [{ "quantity": 1 }, { …
Gareth Miller
  • 332
  • 1
  • 3
  • 10
12
votes
0 answers

What is the proper way to use openapi-generator for generating ktor server stubs

When trying to generate server-side stubs for ktor from openapi, the output to me does not really look very usable. I set up an example project on Github, where the setup can be reviewed. As I need to use maven in my real project, I used it here as…
fnordhusen
  • 121
  • 6
12
votes
1 answer

Ktor no netty_transport_native_epoll_x86_64 in java.library.path

During starting Ktor application, I've got the following logs: java.lang.UnsatisfiedLinkError: no netty_transport_native_epoll_x86_64 in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1871) at…
softshipper
  • 32,463
  • 51
  • 192
  • 400
11
votes
4 answers

JsonFeature for Ktor Client is unresolved

I am starting Ktor based client in android and I want to use any of serializers, currently, the one from kotlinx but the result is the same for others - JsonFeature is not found (highlighted read in the snippet below). What am I missing? class…
Andy Victors
  • 335
  • 2
  • 9
1
2 3
73 74