zio / zio-http

A next-generation Scala framework for building scalable, correct, and efficient HTTP clients and servers
https://zio.dev/zio-http
Apache License 2.0
782 stars 392 forks source link

Document an example demonstrating integration with twirl #423

Closed girdharshubham closed 2 years ago

girdharshubham commented 2 years ago

Description

Twirl is a powerful Scala-based template engine. We'd need a document and an example demonstrating integration of zio-http with twirl.

Example

import play.twirl.api. import zhttp.http. import zhttp.service.Server import zio.{ExitCode, URIO}

object ZIOHttp extends zio.App { val app: HttpApp[Any, Nothing] = HttpApp.collect { case Method.GET -> Root => { val response: UResponse = Response .text(html .index("John Doe", 42) .toString() )

  response
    .asInstanceOf[UHttpResponse]
    .copy(headers = List(Header.custom("content-type", "text/html")))
}

}

override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = Server.start(80, app).exitCode

}

* Build configuration
```scala
project.enablePlugins(SbtTwirl)

Specs

brbrown25 commented 2 years ago

If I have some time I’d be interested in picking this up :)

domdorn commented 2 years ago

@brbrown25 are you still on to this?

brbrown25 commented 2 years ago

@brbrown25 are you still on to this?

I didn't get a chance to, so feel free to pick it up. Otherwise I'll have some time this week to hack on it.

brbrown25 commented 2 years ago

@tusharmath I'm gonna start working on this today and hope to have a PR by EOW, depending on schedule. I'm think this is a change that would need to be added to the example project?

amitksingh1490 commented 2 years ago

Available in 1.0.0.0-RC18