Configuration

class Configuration

Configuration type for ContentNegotiation feature

Constructors

<init>

Configuration()

Configuration type for ContentNegotiation feature

Functions

accept

fun accept(contributor: AcceptHeaderContributor): Unit

Register a custom accepted content types contributor. A contributor function takes ApplicationCall and a list of content types accepted according to HttpHeaders.Accept header or provided by the previous contributor if exists. Result of this contributor should be a list of accepted content types with quality. A contributor could either keep or replace input list of accepted content types depending on use-case. For example a contributor taking format=json request parameter could replace the original content types list with the specified one from the uri argument. Note that the returned list of accepted types will be sorted according to quality using sortedByQuality so a custom contributor may keep it unsorted and should not rely on input list order.

register

fun <T : ContentConverter> register(
    contentType: ContentType,
    converter: T,
    configuration: T.() -> Unit = {}
): Unit

Registers a contentType to a specified converter with an optional configuration script for converter

Extension Functions

gson

fun Configuration.gson(
    contentType: ContentType = ContentType.Application.Json,
    block: GsonBuilder.() -> Unit = {}
): Unit

Register GSON to ContentNegotiation feature

jackson

fun Configuration.jackson(
    contentType: ContentType = ContentType.Application.Json,
    block: ObjectMapper.() -> Unit = {}
): Unit

Register Jackson converter into ContentNegotiation feature

json

fun Configuration.json(
    json: Json = Json.Default,
    module: SerializersModule = EmptySerializersModule,
    contentType: ContentType = ContentType.Application.Json
): Unit
fun Configuration.json(
    json: Json = DefaultJson,
    contentType: ContentType = ContentType.Application.Json
): Unit

Register application/json (or another specified contentType) content type to ContentNegotiation feature using kotlinx.serialization.

serialization

fun Configuration.serialization(
    contentType: ContentType,
    format: BinaryFormat
): Unit

Register kotlinx.serialization converter into ContentNegotiation feature with the specified contentType and binary format (such as CBOR, ProtoBuf)

fun Configuration.serialization(
    contentType: ContentType,
    format: StringFormat
): Unit

Register kotlinx.serialization converter into ContentNegotiation feature with the specified contentType and string format (such as Json)

fun Configuration.serialization(): Unit
fun Configuration.serialization(
    contentType: ContentType
): Unit
fun Configuration.serialization(
    contentType: ContentType,
    json: Json
): Unit

Register kotlinx.serialization converter into ContentNegotiation feature

serialization0

fun Configuration.serialization0(
    contentType: ContentType = ContentType.Application.Json,
    json: Json = DefaultJson
): Unit