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
797 stars 401 forks source link

Help: need guide to use render html static page #1954

Open ghost opened 1 year ago

ghost commented 1 year ago

need some guide to make zio-http working with render html static page. Like: https://www.playframework.com/documentation/2.8.x/ScalaTemplates

What's the best practice to render html?

SoerenSilkjaer commented 1 year ago

Here is an old commit with a zio-http twirl example project. Beware this was made for an earlier version of zio-http, and I dont know if you can migrate it to the latest version.

https://github.com/zio/zio-http/commit/a8e9fbeb52a11f5e408c0e94e87d0ae82997a106

jamesward commented 1 year ago

The ZIO HTTP Handler.template option is decent but not documented. Another option is Scala Tags. Twirl integration works and provides a decent migration path for Play users but doesn't seem like the right choice for anyone who can choose. Overall I'd vote for improving and documenting Handler.template :)

baldram commented 1 year ago

Twirl integration works [...] but doesn't seem like the right choice for anyone who can choose.

@jamesward What's the issue with Twirl? Any drawbacks or reasons to steer clear?

Overall I'd vote for improving and documenting Handler.template :)

Documentation aside, do you know any repo or Gist with a good example? Here's a cool example, looks solid. So, this is the route you'd recommend? Still keen on hearing about Twirl though ;)

jamesward commented 1 year ago

Here is where I use Handler.template https://github.com/jamesward/javadoccentral/blob/master/src/main/scala/App.scala#L29

From what I remember, the primary reason I decided not to use Twirl was due to the lack of Scala 3 language support. ie I don't think I can use braceless syntax in Twirl templates. But maybe I'm remembering things wrong.

baldram commented 1 year ago

not to use Twirl was due to the lack of Scala 3 language support

Oh, good point! Thanks.