emptygif
Bahasa: Bahasa Indonesia

Semua bahasa dan framework

http4k Kotlin

Snippet Kotlin untuk http4k yang menjawab request ke /pixel.gif dengan empty GIF, yang di-decode sekali saat startup.

http4k Kotlin

Instal
implementation("org.http4k:http4k-core:6.60.0.0")
File
Pixel.kt
import org.http4k.core.Method.GET
import org.http4k.core.MemoryBody
import org.http4k.core.Response
import org.http4k.core.Status.Companion.OK
import org.http4k.routing.bind
import org.http4k.routing.routes
import org.http4k.server.SunHttp
import org.http4k.server.asServer
import java.util.Base64

private val GIF = Base64.getDecoder().decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")

val app = routes(
    "/pixel.gif" bind GET to {
        Response(OK)
            .header("Content-Type", "image/gif")
            .header("Cache-Control", "no-store")
            .body(MemoryBody(GIF))
    },
)

fun main() {
    app.asServer(SunHttp(8080)).start()
}

Kami telah menjalankan snippet ini dan membandingkan byte yang dikembalikannya.

Periksa

curl -sI http://localhost:8080/pixel.gif

Situs resmi: http4k

Lainnya dalam Kotlin