You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For reference, here's a list of some combinators from **servant**:
309
309
310
-
> - `Delete`, `Get`, `Patch`, `Post`, `Put`: these do not become arguments. They provide the return type of handlers, which usually is `ExceptT ServantErr IO <something>`.
310
+
> - `Delete`, `Get`, `Patch`, `Post`, `Put`: these do not become arguments. They provide the return type of handlers, which usually is `Handler <something>`.
311
311
> - `Capture "something" a` becomes an argument of type `a`.
312
312
> - `QueryParam "something" a`, `Header "something" a` all become arguments of type `Maybe a`, because there might be no value at all specified by the client for these.
313
313
> - `QueryFlag "something"` gets turned into an argument of type `Bool`.
# or just point your browser to http://localhost:8081/persons
602
602
```
603
603
604
-
## The `ExceptT ServantErr IO` monad
604
+
## The `Handler` monad
605
605
606
-
At the heart of the handlers is the monad they run in, namely `ExceptT
607
-
ServantErr IO`
608
-
([haddock documentation for `ExceptT`](http://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Except.html#t:ExceptT)).
606
+
At the heart of the handlers is the monad they run in, namely `ExceptT ServantErr IO`
607
+
([haddock documentation for `ExceptT`](http://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Except.html#t:ExceptT)), which is aliased as `Handler`.
609
608
One might wonder: why this monad? The answer is that it is the
610
609
simplest monad with the following properties:
611
610
@@ -621,7 +620,7 @@ Let's recall some definitions.
621
620
newtype ExceptT e m a = ExceptT (m (Either e a))
622
621
```
623
622
624
-
In short, this means that a handler of type `ExceptT ServantErr IO a` is simply
623
+
In short, this means that a handler of type `Handler a` is simply
625
624
equivalent to a computation of type `IO (Either ServantErr a)`, that is, an IO
626
625
action that either returns an error or a result.
627
626
@@ -688,7 +687,7 @@ module. If you want to use these values but add a body or some headers, just
688
687
use record update syntax:
689
688
690
689
``` haskell
691
-
failingHandler :: ExceptT ServantErr IO ()
690
+
failingHandler :: Handler ()
692
691
failingHandler = throwError myerr
693
692
694
693
where myerr :: ServantErr
@@ -826,11 +825,11 @@ However, you have to be aware that this has an effect on the type of the
826
825
corresponding `Server`:
827
826
828
827
``` haskell ignore
829
-
Server UserAPI3 = (Int -> ExceptT ServantErr IO User)
830
-
:<|> (Int -> ExceptT ServantErr IO ())
828
+
Server UserAPI3 = (Int -> Handler User)
829
+
:<|> (Int -> Handler ())
831
830
832
-
Server UserAPI4 = Int -> ( ExceptT ServantErr IO User
833
-
:<|> ExceptT ServantErr IO ()
831
+
Server UserAPI4 = Int -> ( Handler User
832
+
:<|> Handler ()
834
833
)
835
834
```
836
835
@@ -842,10 +841,10 @@ computations in `ExceptT`, with no arguments. In other words:
842
841
server8 :: Server UserAPI3
843
842
server8 = getUser :<|> deleteUser
844
843
845
-
where getUser :: Int -> ExceptT ServantErr IO User
0 commit comments