emptygif
భాష: తెలుగు

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

http4s Scala

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

http4s Scala

ఇన్‌స్టాల్
libraryDependencies ++= Seq("org.http4s" %% "http4s-ember-server" % "0.23.37", "org.http4s" %% "http4s-dsl" % "0.23.37")
ఫైల్
Main.scala
import cats.effect.{IO, IOApp}
import com.comcast.ip4s.*
import org.http4s.*
import org.http4s.dsl.io.*
import org.http4s.ember.server.EmberServerBuilder
import org.http4s.headers.{`Cache-Control`, `Content-Type`}

object Main extends IOApp.Simple:
  private val gif = java.util.Base64.getDecoder.decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
  private val PixelPath = Uri.Path.unsafeFromString("/pixel.gif")

  private val routes = HttpRoutes.of[IO] { case GET -> PixelPath =>
    Ok(gif, `Content-Type`(MediaType.image.gif), `Cache-Control`(CacheDirective.`no-store`))
  }

  val run = EmberServerBuilder
    .default[IO]
    .withHost(ipv4"0.0.0.0")
    .withPort(port"8080")
    .withHttpApp(routes.orNotFound)
    .build
    .useForever

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

చెక్ చేయండి

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

అధికారిక సైట్: http4s

Scala లో మరిన్ని