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

org.http4k.connect.kafka.schemaregistry.endpoints.GetSubjectVersion.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.kafka.schemaregistry.action.RegisteredSchemaVersion
import org.http4k.connect.kafka.schemaregistry.model.SchemaId
import org.http4k.connect.kafka.schemaregistry.model.Subject
import org.http4k.connect.kafka.schemaregistry.model.Version
import org.http4k.connect.storage.Storage
import org.http4k.core.Body
import org.http4k.core.ContentType
import org.http4k.core.Method.GET
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.with
import org.http4k.lens.Path
import org.http4k.routing.bind

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

        schemas["$subject:$version"]
            ?.let {
                Response(Status.OK)
                    .with(
                        Body.auto(contentType = ContentType.SCHEMA_REGISTRY).toLens() of
                            RegisteredSchemaVersion(
                                Subject.of(subject),
                                SchemaId.of(version.toInt()),
                                Version.of(version.toInt()),
                                it
                            )
                    )
            }
            ?: Response(Status.NOT_FOUND)
    }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy