ZIO Http is a scala library for building http apps. It is powered by ZIO and netty and aims at being the defacto solution for writing, highly scalable and performant web applications using idiomatic scala.
Check out the full documentation here: Documentation
Table of Contents
A simple Http server can be built using a few lines of code.
import zio._
import zhttp.http._
import zhttp.service.Server
object HelloWorld extends App {
val app = Http.collect[Request] {
case Method.GET -> Root / "text" => Response.text("Hello World!")
}
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
Server.start(8090, app).exitCode
}
You can checkout more examples in the example project —
- Simple Server
- Advanced Server
- WebSocket Server
- Streaming Response
- Simple Client
- File Streaming
- Authentication
Setup via build.sbt
libraryDependencies += "io.d11" %% "zhttp" % "[version]"
libraryDependencies += "io.d11" %% "zhttp-test" % "[version]" % Test
NOTE: Currently ZIO Http is compatible with ZIO 1.x
only. The library will migrate to ZIO 2.x
as soon as a stable release is published.
You can use the sbt-revolver plugin to start the server and run it in watch mode using ~ reStart
command on the SBT console.