I am creating a ZioHttp Rest endpoint...
For a Json request I want to return Json response ...
I'm able to retrun logs, print lines but not sure how to return json response...
Here's my code:
import zio.{Console, _}
import zhttp._
import zhttp.http._
import zhttp.service.Server
import zio.json.{DeriveJsonEncoder, JsonEncoder}
//import java.io.Console
object ZioHttp extends ZIOAppDefault {
  val port = 9000
  val app: Http[Any, Nothing, Request, Response] = Http.collect[Request] {
    case Method.GET -> !! / "zioCollector" => Response.text("Hello, Http server This is Mohammed Mukhtar Ali!!")
  }
  case class Events(experimentId: String,
                    variantId: String,
                    accountId: String,
                    deviceId: String,
                    date: Int)
  object Events {
    implicit val encoder: JsonEncoder[Events] = DeriveJsonEncoder.gen[Events]
  }
  val zApp: UHttpApp = Http.collectZIO[Request] {
    case Method.POST -> !! / "zioCollector" =>
      Random.nextIntBetween(3, 5).map(n => Response.text("Hello " * n + "server2!"))
  }
  //  val zApp2: UHttpApp = Http.collectZIO[Request] {
  //    case Method.POST -> !! / "zioCollector" =>
  //      Random.nextIntBetween(3, 5).map(n => Response.json()
  //  }
  val combied = app ++ zApp
  val httpProgram = for {
    _ <- Console.printLine(s"Starting server at http://localhost:$port")
    _ <- Server.start(port, combied)
  } yield ()
  override def run = httpProgram
}
I'm a beginner with Zio and scala, appreatiate any help proided!
 
                        
Not an expert for zio-http (nor zio in general), but this code works for me: