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
787 stars 396 forks source link

Better Example With Layers #1569

Open 8bitreid opened 2 years ago

8bitreid commented 2 years ago

What is not easy to do right now? It is not clear how to get started using zhttp with a dependency for your HttpApp or something for your R

Describe the solution you'd like A simple example of HttpApp where there is an R that does the "logic" doesn't have to be anything complex.

Why is it important? This is a great project, but to newcomers the idea of returning raw string text or json is not appealing. This will give a clear and straightforward example of how to pick up and put zhttp on top of an existing service.

Additional context For an existing project in other frameworks I know how to write a service with functions A => B but in the examples here all I see are examples of Path => String and this is quick and easy. However, if I have a dependency like ServiceA there are no examples with R on any documentation.

fernanluyano commented 1 year ago

The documentation is really here. I can't find anywhere how to provide layers to my app. With io.d11 was as simple as Server .start(8080, endpoints) .provide( Layer1.live, Layer2.live)

8bitreid commented 1 year ago

The documentation is really here. I can't find anywhere how to provide layers to my app.

With io.d11 was as simple as

Server

    .start(8080, endpoints)

    .provide(

      Layer1.live,

      Layer2.live)

Does this work?

https://github.com/8bitreid/zio-examples/blob/main/src/main/scala/example/zhttp/ZhttpServer.scala

fernanluyano commented 1 year ago

Yeah, that helps, thanks