please wiat for haskell-servant/servant#1314 to be released instead.
This set of packages allows you to write servant code for end-points
whose response types are open unions of types (UVerb
is short for
UnionVerb
). It should be merged into the resp. servant packages at
some point in the future, but mostly for the sake of making it easier
to maintan it; it's ready to be used now.
Take a look at ./example/Main.hs
to get an idea how it works.
-
UStream
(likeStream
) -
NoContentUVerb
(likeNoContentVerb
) - Tests
- make
./example
a self-contained package. - convert this list into issues.
There is an issue from 2017 discussing handlers that return different types under different circumstances.
servant-checked-exceptions is a good solution to the problem, but it restricts the user to JSON and a very specific envelop encoding for the union type, which is often not acceptable. (One good reason for this design choice is that it makes writing clients easier, where you need to get to the union type from one representative, and you don't want to run several parsers in the hope that the ones that should will always error out so you can try until the right one returns a value.)
servnat-exceptions is another shot at at the problem. It is inspired by servant-checked-exceptions, so it may be worth taking a closer look. The README also claims that cardano-sl also has some code for generalized error handling.
We have copied some code from world-peace. The package itself wasn't flexible enough, and we had to use sop-core to implement servant-uverb-server.
Also: https://lukwagoallan.com/posts/unifying-servant-server-error-responses