emptygif
ਭਾਸ਼ਾ: ਪੰਜਾਬੀ

ਸਾਰੀਆਂ ਭਾਸ਼ਾਵਾਂ ਅਤੇ ਫਰੇਮਵਰਕ

http4s Scala

http4s ਲਈ Scala ਸਨਿੱਪਟ, ਜੋ /pixel.gif ਦੀਆਂ ਬੇਨਤੀਆਂ ਦਾ ਜਵਾਬ ਖਾਲੀ GIF ਨਾਲ ਦਿੰਦਾ ਹੈ; 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 ਵਿੱਚ ਹੋਰ