zio-http icon indicating copy to clipboard operation
zio-http copied to clipboard

Move client and server to interfaces + implementations + layers

Open jdegoes opened this issue 2 years ago • 5 comments

Is your feature request related to a problem? Please describe.

The server and client are objects, whose methods use the environment to obtain their dependencies. This was a ZIO 1.0 pattern. In ZIO 2, it's more idiomatic for such functionality to be moved to service traits, whose classes consume dependencies through constructors, and whose construction is itself described by a layer.

Describe the solution you'd like

There should exist Client and Server traits, which define what it means for something to be a Client or Server, and the dependencies and resources necessary to create these should be bundled up into layers.

This will allow the client and server to consume resources, have their own dependencies, and possibly even have test implementations, while at the same time following the newer ZIO 2 module pattern, which embraces constructor-based dependency injection.

Describe alternatives you've considered

None.

jdegoes avatar Sep 12 '22 23:09 jdegoes

I'll do this.

adamgfraser avatar Sep 13 '22 16:09 adamgfraser

Actually @gciuloaica is already on this!

adamgfraser avatar Sep 13 '22 16:09 adamgfraser

One change that we should consider while doing this change is to make sure that the client and the server use the same event loop and the same transport.

tusharmath avatar Sep 14 '22 07:09 tusharmath

@devsprint See comment from @tusharmath on sharing event loop & transport between client & server.

jdegoes avatar Sep 15 '22 14:09 jdegoes

@jdegoes @tusharmath the event loop and transport between client and sever sharing will be in a new PR.

devsprint avatar Sep 15 '22 15:09 devsprint

I think this can be closed now

vigoo avatar Feb 19 '23 09:02 vigoo