All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lightningkite.lightningserver.serialization.FormDataHandler.kt Maven / Gradle / Ivy

The newest version!
package com.lightningkite.lightningserver.serialization

import com.lightningkite.lightningserver.core.ContentType
import com.lightningkite.lightningserver.http.HttpContent
import kotlinx.serialization.KSerializer
import kotlinx.serialization.properties.Properties

open class FormDataHandler(
    val properties: () -> Properties
) : Serialization.HttpContentHandler {
    override val contentType: ContentType = ContentType.Application.FormUrlEncoded
    override suspend fun  invoke(content: HttpContent, serializer: KSerializer): T {
        return properties().decodeFromFormData(serializer, content.text())
    }

    override suspend fun  invoke(contentType: ContentType, serializer: KSerializer, value: T): HttpContent {
        return HttpContent.Text(
            properties().encodeToFormData(serializer, value),
            contentType
        )
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy