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.http._
import zio.http.Server
import zio._
object HelloWorld extends ZIOAppDefault {
val app: HttpApp[Any, Nothing] = Http.collect[Request] {
case Method.GET -> !! / "text" => Response.text("Hello World!")
}
override val run =
Server.start(8090, app)
}
You can checkout more examples in the example project —
- Simple Server
- Advanced Server
- WebSocket Server
- Streaming Response
- Simple Client
- File Streaming
- Basic Authentication
- JWT Authentication Client
- JWT Authentication Server
- Edit the RunSettings - modify
className
to the example you'd like to run. - From sbt shell, run
~example/reStart
. You should seeServer started on port: 8090
. - Send curl request for defined
http Routes
, for eg :curl -i "http://localhost:8090/text"
forexample.HelloWorld
.
Setup via build.sbt
libraryDependencies += "io.d11" %% "zhttp" % "[version]"
libraryDependencies += "dev.zio" %% "zio-http" % "[version]"
NOTE: ZIO Http is compatible with ZIO 1.x
and ZIO 2.x
.
You can use the sbt-revolver plugin to start the server and run it in watch mode using ~ reStart
command on the SBT console.