jk2018
02/24/2020, 10:32 PMNikky
02/25/2020, 8:23 AMNikky
02/25/2020, 8:56 AMcall.receiveMultipart()
and manually receiving all parameters ?waltermcq
02/25/2020, 9:12 PMNiro
02/26/2020, 3:00 PMprivate val client by lazy {
HttpClient(engine) {
install(JsonFeature) {
serializer = KotlinxSerializer(Json.nonstrict).apply {
setMapper(Todo::class, Todo.serializer())
}
}
install(WebSockets)
}
}
suspend fun fetchNotes(): List<Todo> {
val jsonString2 = client.get<String> {
url("$baseUrl/todos")
}
return Json.nonstrict.parse(multiNoteSerializer, jsonString2)
}
Jeff
02/27/2020, 12:03 PMSaood
02/27/2020, 4:21 PMIos.create {
configureSession {
}
}
Delegate method for certificate validation
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Swift.Void)
Narek Mailian
02/28/2020, 11:29 AMJan Stoltman
02/28/2020, 12:55 PMcodec
02/28/2020, 7:41 PMlog()
function… because it’s not in the
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3
library…Muh Rahmatullah
02/29/2020, 6:47 PMcall.receive<Foo>()
and the error is
java.lang.UnsupportedOperationException: This function has a reified type parameter and thus can only be inlined at compilation time, not called directly.
this is the post handler:
fun Route.createMovie(movies: MutableList<Movie>) {
post("/movie") {
val id = Random.nextInt(1, 100000)
println("header ${call.request.headers["Content-Type"]}")
if(movies.find { it.id == id.toString() } != null) {
// this is example to modify status code in the response and assign the value to the response wrapper
call.response.status(value = HttpStatusCode.BadRequest)
call.respond(Response(data = null, code = call.response.status()?.value, message = "Movie with $id already exist"))
} else {
val payload = call.receive<Movie>()
println(payload)
movies.add(payload)
call.respond(Response(data = movies, code = 200, message = "OK"))
}
}
}
and my Application
fun Application.module(testing: Boolean = false) {
val movies = initData()
install(ContentNegotiation) {
gson {
setPrettyPrinting()
}
}
routing {
get("/") {
call.respondText("A very simple rest api using k-tor!", contentType = ContentType.Text.Plain)
}
movies(movies)
movieById(movies)
deleteById(movies)
createMovie(movies)
}
}
Also, I already set the Content-type to application/json when sending the request. TIA, any help would be greatribesg
03/01/2020, 12:42 PM/example
gets <http://localhost/example>
. Is it intended?sultanofcardio
03/02/2020, 7:16 PMShan
03/02/2020, 11:00 PMAndroidEngineConfig
set up in a way that if the method isn't GET
, HEAD
or DELETE
to set the content type to ContentType.Application.Json
. This is fine for all of my POST
requests with bodies, but I now need to make a POST
request without a body (it is only a path with an Empty response), and I am getting:
io.ktor.http.UnsafeHeaderException: Header Content-Type is controlled by the engine and cannot be set explicitly
Is there any way I can override the Content-Type
for this single request, or is there a way I can programmatically set it for each individual request?Henrik
03/03/2020, 11:07 AMprivate val client = HttpClient()
val result: ByteArray = client.get {
url(url.toString())
}
sultanofcardio
03/03/2020, 5:48 PM1.3.70-release-IJ2019.3-1
of the Kotlin plugin in IntelliJ has broken ktor builds. The source of this stack trace is the declaration of the Application.module
extension functionribesg
03/04/2020, 9:45 AMtylerwilson
03/04/2020, 6:12 PMjava.lang.NoSuchFieldError: No field Companion of type Lkotlinx/serialization/json/Json$Companion; in class Lkotlinx/serialization/json/Json; or its superclasses (declaration of 'kotlinx.serialization.json.Json' appears in /data/app/com.webappclouds.salonbiz-ZLc1BlPrwYueYBzBSLTUTg==/base.apk!classes3.dex)
John Peña
03/04/2020, 9:51 PMTestApplicationCall
without going through all the tediousness of making a test server, test engine, test request, etcnapperley
03/04/2020, 10:55 PMnapperley
03/05/2020, 1:35 AMnapperley
03/05/2020, 1:41 AMrrva
03/05/2020, 10:36 AMgabin
03/05/2020, 2:42 PMException in thread "main" java.lang.NoClassDefFoundError: kotlinx/serialization/ShorthandsKt
at io.ktor.client.features.json.serializer.KotlinxSerializerKt.buildSerializer(KotlinxSerializer.kt:91)
at io.ktor.client.features.json.serializer.KotlinxSerializerKt.access$buildSerializer(KotlinxSerializer.kt:1)
at io.ktor.client.features.json.serializer.KotlinxSerializer.write(KotlinxSerializer.kt:69)
at io.ktor.client.features.json.JsonFeature$Feature$install$1.invokeSuspend(JsonFeature.kt:101)
at io.ktor.client.features.json.JsonFeature$Feature$install$1.invoke(JsonFeature.kt)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:273)
Can you point me what’s wrong?
ktor 1.3.1, serialization 0.20.0gabin
03/05/2020, 4:56 PMinstall(Logging) {
logger = Logger.ANDROID
level = LogLevel.ALL
}
implementation "io.ktor:ktor-client-logging-jvm:$ktorVersion"
in logs I only see exception:
2020-03-05 16:16:33.829 1383-1383/? W/System.err: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
2020-03-05 16:16:33.829 1383-1383/? W/System.err: SLF4J: Defaulting to no-operation (NOP) logger implementation
2020-03-05 16:16:33.829 1383-1383/? W/System.err: SLF4J: See <http://www.slf4j.org/codes.html#StaticLoggerBinder> for further details.
is there a way to make it work ?christophsturm
03/06/2020, 10:56 AMCLOVIS
03/06/2020, 11:21 AM/account/auth/
) which I should send a JSON object to, which contains a field username
and a field password
. It should return a JSON object that contains a token
field.
I want to use Kotlinx.Serialization to generate the JSON objects, so I started with:
@Serializable
private data class ApiUsernamePassword(val username: String, val password: String)
and I do my request like this:
val client = HttpClient() {
install(JsonFeature) {
serializer = KotlinxSerializer()
}
}
val res = <http://client.post|client.post><String> {
url("<http://localhost:8000/account/auth/>")
body = ApiUsernamePassword(username, password)
}
On the JVM, I get this error:
Companion
java.lang.NoSuchFieldError: Companion
at io.ktor.client.features.json.serializer.KotlinxSerializer.<init>(KotlinxSerializer.kt:22)
(I can send the full stacktrace if needed)
On JS, I get this error:
TypeError: Cannot read property 'plain' of undefined
at new KotlinxSerializer (<http://localhost:9876/absolute/[REDACTED]/adapter-browser.js?fb6a5f1e12e8cc2bf794189b2b55f22def38ca94:157371:29>)
I've tried Googling it but I don't get any meaningul/related results for both of those errors... Did anyone encounter this before? I also tried adding an empty companion object to my serializable class but it didn't change anything. (all of the above is in the common module, if that's relevant)gabin
03/06/2020, 12:02 PMtim
03/07/2020, 3:42 PMjpg
03/08/2020, 10:41 AM