Skip to main content

HTTP Server

import zio.http._
import zio.http.Server
import zio._

object HelloWorld extends App {

// Create HTTP route
val app: HttpApp[Any, Nothing] = Http.collect[Request] {
case Method.GET -> !! / "text" => Response.text("Hello World!")
case Method.GET -> !! / "json" => Response.json("""{"greetings": "Hello World!"}""")
}

// Run it like any simple app
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
Server.start(8090, app.silent).exitCode
}