Hoist server implementation.
Sometimes our cherished
Handler monad isn't quite the type
you'd like for your handlers. Maybe you want to thread some
configuration in a
Reader monad. Or have your types ensure
that your handlers don't do any IO. Use
hoistServer (a
successor of now deprecated
enter).
With
hoistServer, you can provide a function, to convert any
number of endpoints from one type constructor to another. For example
Note: Server Raw can also be entered. It will
be retagged.
>>> import Control.Monad.Reader
>>> type ReaderAPI = "ep1" :> Get '[JSON] Int :<|> "ep2" :> Get '[JSON] String :<|> Raw :<|> EmptyAPI
>>> let readerApi = Proxy :: Proxy ReaderAPI
>>> let readerServer = return 1797 :<|> ask :<|> Tagged (error "raw server") :<|> emptyServer :: ServerT ReaderAPI (Reader String)
>>> let nt x = return (runReader x "hi")
>>> let mainServer = hoistServer readerApi nt readerServer :: Server ReaderAPI