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

org.http4k.connect.kafka.schemaregistry.endpoints.GetSubjectVersions.kt Maven / Gradle / Ivy

There is a newer version: 5.35.1.0
Show newest version
package org.http4k.connect.kafka.schemaregistry.endpoints

import org.apache.avro.Schema
import org.http4k.connect.kafka.schemaregistry.SchemaRegistryMoshi.auto
import org.http4k.connect.storage.Storage
import org.http4k.core.Body
import org.http4k.core.ContentType
import org.http4k.core.Method
import org.http4k.core.Request
import org.http4k.core.Response
import org.http4k.core.SCHEMA_REGISTRY
import org.http4k.core.Status
import org.http4k.core.Status.Companion.OK
import org.http4k.core.with
import org.http4k.lens.Path
import org.http4k.routing.bind

fun getSubjectVersions(schemas: Storage) = "/subjects/{subject}/versions" bind Method.GET to
    { req: Request ->
        val subject = Path.of("subject")(req)

        schemas.keySet().filter { it.startsWith(subject) }
            .map { it.substringAfter(":") }
            .takeIf { it.isNotEmpty() }
            ?.let {
                Response(OK)
                    .with(Body.auto>(contentType = ContentType.SCHEMA_REGISTRY).toLens() of it)
            }
            ?: Response(Status.NOT_FOUND)
    }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy