import zio.http._
import zio.http.Server
import zio.stream.ZStream
import zio._
object StreamingResponse extends App {
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = {
Server.start(8090, app.silent).exitCode
}
val message = Chunk.fromArray("Hello world !\r\n".getBytes(HTTP_CHARSET))
val app: HttpApp[Any, Nothing] = Http.collect[Request] {
case Method.GET -> !! / "health" => Response.ok
case Method.GET -> !! / "stream" =>
Response(
status = Status.OK,
headers = Headers.contentLength(message.length.toLong),
body = Body.fromStream(ZStream.fromChunk(message)),
)
}
}