Why Another ZIO/Http4s Client Example?
There are a couple of sample projects already in existence showing you how to use zio with http4s as a server. So why another?
What this adds to the mix are 3 things that might be independently useful:
- an http4s Authentication/Authorization example
- an example of custom encoding and decoding.
- Tests written using the zio-test module.
For a detailed description of the various libraries you should head on over to the relevant pages. However, if, like me, you sometimes struggle a bit to get everything working together, then this may help. Also, I find some of the other zio coding examples a little daunting, as authors cram multiple concepts into a small sample. These examples are rather more spread out. If this means it’s a little dull for some of you, please go straight to the source code on github!
I don’t claim to be an expert in this stuff. But we do have 4 microservices using this combination already in production and although processing volumes are low, they do seem to work!
I will not attempt to explain either of these libraries, but briefly, ZIO is the latest in a series of scala effects libraries which includes cats.IO and Monix. Http4s is a popular typelevel web framework based on the Blaze server (there is also a client).
The github project contains 4 sets of services that can be treated as a progression from simplest to most complex:
- Hello1 is a very basis “hello world” web service
- Hello2 adds an authentication layer.
- Hello3 is expands 1 with a custom encoding and decoding of an xml object, using scala xml
- Hello4 combines 2 & 3
The blog is broken into