emptygif
భాష: తెలుగు

అన్ని భాషలు, ఫ్రేమ్‌వర్క్‌లు

Spring WebFlux (Kotlin coRouter) Kotlin

/pixel.gif కు వచ్చే రిక్వెస్ట్‌లకు empty GIF తో జవాబిచ్చే, Spring WebFlux (Kotlin coRouter) కోసం Kotlin స్నిపెట్. GIF స్టార్టప్‌లో ఒక్కసారే డీకోడ్ అవుతుంది.

Spring WebFlux (Kotlin coRouter) Kotlin

ఇన్‌స్టాల్
implementation("org.springframework.boot:spring-boot-starter-webflux"); implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
ఫైల్
PixelApplication.kt
రన్
./gradlew bootRun
package com.example.pixel

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean
import org.springframework.http.CacheControl
import org.springframework.http.MediaType
import org.springframework.web.reactive.function.server.bodyValueAndAwait
import org.springframework.web.reactive.function.server.coRouter
import java.util.Base64

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

@SpringBootApplication
class PixelApplication {
    @Bean
    fun pixelRoutes() = coRouter {
        GET("/pixel.gif") {
            ok().contentType(MediaType.IMAGE_GIF)
                .contentLength(GIF.size.toLong())
                .cacheControl(CacheControl.noStore())
                .bodyValueAndAwait(GIF)
        }
    }
}

fun main(args: Array<String>) {
    runApplication<PixelApplication>(*args)
}

మేము ఈ స్నిపెట్‌ను రన్ చేసి, అది తిరిగి ఇచ్చిన బైట్‌లను పోల్చి చూశాం.

చెక్ చేయండి

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

అధికారిక సైట్: Spring WebFlux (Kotlin coRouter)

Kotlin లో మరిన్ని