Skip to main content
Version: ZIO 2.x

Concrete Entity Example

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

* Example to build app on concrete entity
object ConcreteEntity extends App {
// Request
case class CreateUser(name: String)

// Response
case class UserCreated(id: Long)

val user: Http[Any, Nothing, CreateUser, UserCreated] =
Http.collect[CreateUser] { case CreateUser(_) =>

val app: HttpApp[Any, Nothing] =
.contramap[Request](req => CreateUser(req.path.toString)) // Http[Any, Nothing, Request, UserCreated]
.map(userCreated => Response.text( // Http[Any, Nothing, Request, Response]

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