git.iko.soy/typeable/servant
on master help sign in
Drop `EitherT` in favor of `ExceptT`
f2f7b06Index Int
servant-client/README.md+2−2
@@ -13,8 +13,8 @@ type MyApi = "books" :> Get '[JSON] [Book] -- GET /books
13myApi :: Proxy MyApi
13myApi :: Proxy MyApi
14myApi = Proxy
14myApi = Proxy
15
15
16−getAllBooks :: EitherT String IO [Book]
16+getAllBooks :: ExceptT String IO [Book]
17−postNewBook :: Book -> EitherT String IO Book
17+postNewBook :: Book -> ExceptT String IO Book
18-- 'client' allows you to produce operations to query an API from a client.
18-- 'client' allows you to produce operations to query an API from a client.
19(getAllBooks :<|> postNewBook) = client myApi host
19(getAllBooks :<|> postNewBook) = client myApi host
20 where host = BaseUrl Http "localhost" 8080
20 where host = BaseUrl Http "localhost" 8080
servant-client/servant-client.cabal+1−2
@@ -33,7 +33,6 @@ library
33 , aeson
33 , aeson
34 , attoparsec
34 , attoparsec
35 , bytestring
35 , bytestring
36− , either
37 , exceptions
36 , exceptions
38 , http-client
37 , http-client
39 , http-client-tls
38 , http-client-tls
@@ -61,10 +60,10 @@ test-suite spec
61 , Servant.Common.BaseUrlSpec
60 , Servant.Common.BaseUrlSpec
62 build-depends:
61 build-depends:
63 base == 4.*
62 base == 4.*
63+ , transformers
64 , aeson
64 , aeson
65 , bytestring
65 , bytestring
66 , deepseq
66 , deepseq
67− , either
68 , hspec == 2.*
67 , hspec == 2.*
69 , http-client
68 , http-client
70 , http-media
69 , http-media
servant-client/src/Servant/Client.hs+30−30
@@ -25,7 +25,7 @@ module Servant.Client
25import Control.Applicative ((<$>))
25import Control.Applicative ((<$>))
26#endif
26#endif
27import Control.Monad
27import Control.Monad
28−import Control.Monad.Trans.Either
28+import Control.Monad.Trans.Except
29import Data.ByteString.Lazy (ByteString)
29import Data.ByteString.Lazy (ByteString)
30import Data.List
30import Data.List
31import Data.Proxy
31import Data.Proxy
@@ -50,8 +50,8 @@ import Servant.Common.Req
50-- > myApi :: Proxy MyApi
50-- > myApi :: Proxy MyApi
51-- > myApi = Proxy
51-- > myApi = Proxy
52-- >
52-- >
53−-- > getAllBooks :: EitherT String IO [Book]
53+-- > getAllBooks :: ExceptT String IO [Book]
54−-- > postNewBook :: Book -> EitherT String IO Book
54+-- > postNewBook :: Book -> ExceptT String IO Book
55-- > (getAllBooks :<|> postNewBook) = client myApi host
55-- > (getAllBooks :<|> postNewBook) = client myApi host
56-- > where host = BaseUrl Http "localhost" 8080
56-- > where host = BaseUrl Http "localhost" 8080
57client :: HasClient layout => Proxy layout -> BaseUrl -> Client layout
57client :: HasClient layout => Proxy layout -> BaseUrl -> Client layout
@@ -76,8 +76,8 @@ class HasClient layout where
76-- > myApi :: Proxy MyApi
76-- > myApi :: Proxy MyApi
77-- > myApi = Proxy
77-- > myApi = Proxy
78-- >
78-- >
79−-- > getAllBooks :: EitherT String IO [Book]
79+-- > getAllBooks :: ExceptT String IO [Book]
80−-- > postNewBook :: Book -> EitherT String IO Book
80+-- > postNewBook :: Book -> ExceptT String IO Book
81-- > (getAllBooks :<|> postNewBook) = client myApi host
81-- > (getAllBooks :<|> postNewBook) = client myApi host
82-- > where host = BaseUrl Http "localhost" 8080
82-- > where host = BaseUrl Http "localhost" 8080
83instance (HasClient a, HasClient b) => HasClient (a :<|> b) where
83instance (HasClient a, HasClient b) => HasClient (a :<|> b) where
@@ -102,7 +102,7 @@ instance (HasClient a, HasClient b) => HasClient (a :<|> b) where
102-- > myApi :: Proxy MyApi
102-- > myApi :: Proxy MyApi
103-- > myApi = Proxy
103-- > myApi = Proxy
104-- >
104-- >
105−-- > getBook :: Text -> EitherT String IO Book
105+-- > getBook :: Text -> ExceptT String IO Book
106-- > getBook = client myApi host
106-- > getBook = client myApi host
107-- > where host = BaseUrl Http "localhost" 8080
107-- > where host = BaseUrl Http "localhost" 8080
108-- > -- then you can just use "getBook" to query that endpoint
108-- > -- then you can just use "getBook" to query that endpoint
@@ -129,7 +129,7 @@ instance
129#endif
129#endif
130 -- See https://downloads.haskell.org/~ghc/7.8.2/docs/html/users_guide/type-class-extensions.html#undecidable-instances
130 -- See https://downloads.haskell.org/~ghc/7.8.2/docs/html/users_guide/type-class-extensions.html#undecidable-instances
131 (MimeUnrender ct a, cts' ~ (ct ': cts)) => HasClient (Delete cts' a) where
131 (MimeUnrender ct a, cts' ~ (ct ': cts)) => HasClient (Delete cts' a) where
132− type Client (Delete cts' a) = EitherT ServantError IO a
132+ type Client (Delete cts' a) = ExceptT ServantError IO a
133 clientWithRoute Proxy req baseurl =
133 clientWithRoute Proxy req baseurl =
134 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodDelete req [200, 202] baseurl
134 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodDelete req [200, 202] baseurl
135
135
@@ -140,7 +140,7 @@ instance
140 {-# OVERLAPPING #-}
140 {-# OVERLAPPING #-}
141#endif
141#endif
142 HasClient (Delete cts ()) where
142 HasClient (Delete cts ()) where
143− type Client (Delete cts ()) = EitherT ServantError IO ()
143+ type Client (Delete cts ()) = ExceptT ServantError IO ()
144 clientWithRoute Proxy req baseurl =
144 clientWithRoute Proxy req baseurl =
145 void $ performRequestNoBody H.methodDelete req [204] baseurl
145 void $ performRequestNoBody H.methodDelete req [204] baseurl
146
146
@@ -153,7 +153,7 @@ instance
153 -- See https://downloads.haskell.org/~ghc/7.8.2/docs/html/users_guide/type-class-extensions.html#undecidable-instances
153 -- See https://downloads.haskell.org/~ghc/7.8.2/docs/html/users_guide/type-class-extensions.html#undecidable-instances
154 ( MimeUnrender ct a, BuildHeadersTo ls, cts' ~ (ct ': cts)
154 ( MimeUnrender ct a, BuildHeadersTo ls, cts' ~ (ct ': cts)
155 ) => HasClient (Delete cts' (Headers ls a)) where
155 ) => HasClient (Delete cts' (Headers ls a)) where
156− type Client (Delete cts' (Headers ls a)) = EitherT ServantError IO (Headers ls a)
156+ type Client (Delete cts' (Headers ls a)) = ExceptT ServantError IO (Headers ls a)
157 clientWithRoute Proxy req baseurl = do
157 clientWithRoute Proxy req baseurl = do
158 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodDelete req [200, 202] baseurl
158 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodDelete req [200, 202] baseurl
159 return $ Headers { getResponse = resp
159 return $ Headers { getResponse = resp
@@ -169,7 +169,7 @@ instance
169 {-# OVERLAPPABLE #-}
169 {-# OVERLAPPABLE #-}
170#endif
170#endif
171 (MimeUnrender ct result) => HasClient (Get (ct ': cts) result) where
171 (MimeUnrender ct result) => HasClient (Get (ct ': cts) result) where
172− type Client (Get (ct ': cts) result) = EitherT ServantError IO result
172+ type Client (Get (ct ': cts) result) = ExceptT ServantError IO result
173 clientWithRoute Proxy req baseurl =
173 clientWithRoute Proxy req baseurl =
174 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodGet req [200, 203] baseurl
174 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodGet req [200, 203] baseurl
175
175
@@ -180,7 +180,7 @@ instance
180 {-# OVERLAPPING #-}
180 {-# OVERLAPPING #-}
181#endif
181#endif
182 HasClient (Get (ct ': cts) ()) where
182 HasClient (Get (ct ': cts) ()) where
183− type Client (Get (ct ': cts) ()) = EitherT ServantError IO ()
183+ type Client (Get (ct ': cts) ()) = ExceptT ServantError IO ()
184 clientWithRoute Proxy req baseurl =
184 clientWithRoute Proxy req baseurl =
185 performRequestNoBody H.methodGet req [204] baseurl
185 performRequestNoBody H.methodGet req [204] baseurl
186
186
@@ -192,7 +192,7 @@ instance
192#endif
192#endif
193 ( MimeUnrender ct a, BuildHeadersTo ls
193 ( MimeUnrender ct a, BuildHeadersTo ls
194 ) => HasClient (Get (ct ': cts) (Headers ls a)) where
194 ) => HasClient (Get (ct ': cts) (Headers ls a)) where
195− type Client (Get (ct ': cts) (Headers ls a)) = EitherT ServantError IO (Headers ls a)
195+ type Client (Get (ct ': cts) (Headers ls a)) = ExceptT ServantError IO (Headers ls a)
196 clientWithRoute Proxy req baseurl = do
196 clientWithRoute Proxy req baseurl = do
197 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodGet req [200, 203, 204] baseurl
197 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodGet req [200, 203, 204] baseurl
198 return $ Headers { getResponse = resp
198 return $ Headers { getResponse = resp
@@ -220,7 +220,7 @@ instance
220-- > myApi :: Proxy MyApi
220-- > myApi :: Proxy MyApi
221-- > myApi = Proxy
221-- > myApi = Proxy
222-- >
222-- >
223−-- > viewReferer :: Maybe Referer -> EitherT String IO Book
223+-- > viewReferer :: Maybe Referer -> ExceptT String IO Book
224-- > viewReferer = client myApi host
224-- > viewReferer = client myApi host
225-- > where host = BaseUrl Http "localhost" 8080
225-- > where host = BaseUrl Http "localhost" 8080
226-- > -- then you can just use "viewRefer" to query that endpoint
226-- > -- then you can just use "viewRefer" to query that endpoint
@@ -250,7 +250,7 @@ instance
250 {-# OVERLAPPABLE #-}
250 {-# OVERLAPPABLE #-}
251#endif
251#endif
252 (MimeUnrender ct a) => HasClient (Post (ct ': cts) a) where
252 (MimeUnrender ct a) => HasClient (Post (ct ': cts) a) where
253− type Client (Post (ct ': cts) a) = EitherT ServantError IO a
253+ type Client (Post (ct ': cts) a) = ExceptT ServantError IO a
254 clientWithRoute Proxy req baseurl =
254 clientWithRoute Proxy req baseurl =
255 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPost req [200,201] baseurl
255 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPost req [200,201] baseurl
256
256
@@ -261,7 +261,7 @@ instance
261 {-# OVERLAPPING #-}
261 {-# OVERLAPPING #-}
262#endif
262#endif
263 HasClient (Post (ct ': cts) ()) where
263 HasClient (Post (ct ': cts) ()) where
264− type Client (Post (ct ': cts) ()) = EitherT ServantError IO ()
264+ type Client (Post (ct ': cts) ()) = ExceptT ServantError IO ()
265 clientWithRoute Proxy req baseurl =
265 clientWithRoute Proxy req baseurl =
266 void $ performRequestNoBody H.methodPost req [204] baseurl
266 void $ performRequestNoBody H.methodPost req [204] baseurl
267
267
@@ -273,7 +273,7 @@ instance
273#endif
273#endif
274 ( MimeUnrender ct a, BuildHeadersTo ls
274 ( MimeUnrender ct a, BuildHeadersTo ls
275 ) => HasClient (Post (ct ': cts) (Headers ls a)) where
275 ) => HasClient (Post (ct ': cts) (Headers ls a)) where
276− type Client (Post (ct ': cts) (Headers ls a)) = EitherT ServantError IO (Headers ls a)
276+ type Client (Post (ct ': cts) (Headers ls a)) = ExceptT ServantError IO (Headers ls a)
277 clientWithRoute Proxy req baseurl = do
277 clientWithRoute Proxy req baseurl = do
278 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodPost req [200, 201] baseurl
278 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodPost req [200, 201] baseurl
279 return $ Headers { getResponse = resp
279 return $ Headers { getResponse = resp
@@ -289,7 +289,7 @@ instance
289 {-# OVERLAPPABLE #-}
289 {-# OVERLAPPABLE #-}
290#endif
290#endif
291 (MimeUnrender ct a) => HasClient (Put (ct ': cts) a) where
291 (MimeUnrender ct a) => HasClient (Put (ct ': cts) a) where
292− type Client (Put (ct ': cts) a) = EitherT ServantError IO a
292+ type Client (Put (ct ': cts) a) = ExceptT ServantError IO a
293 clientWithRoute Proxy req baseurl =
293 clientWithRoute Proxy req baseurl =
294 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPut req [200,201] baseurl
294 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPut req [200,201] baseurl
295
295
@@ -300,7 +300,7 @@ instance
300 {-# OVERLAPPING #-}
300 {-# OVERLAPPING #-}
301#endif
301#endif
302 HasClient (Put (ct ': cts) ()) where
302 HasClient (Put (ct ': cts) ()) where
303− type Client (Put (ct ': cts) ()) = EitherT ServantError IO ()
303+ type Client (Put (ct ': cts) ()) = ExceptT ServantError IO ()
304 clientWithRoute Proxy req baseurl =
304 clientWithRoute Proxy req baseurl =
305 void $ performRequestNoBody H.methodPut req [204] baseurl
305 void $ performRequestNoBody H.methodPut req [204] baseurl
306
306
@@ -312,7 +312,7 @@ instance
312#endif
312#endif
313 ( MimeUnrender ct a, BuildHeadersTo ls
313 ( MimeUnrender ct a, BuildHeadersTo ls
314 ) => HasClient (Put (ct ': cts) (Headers ls a)) where
314 ) => HasClient (Put (ct ': cts) (Headers ls a)) where
315− type Client (Put (ct ': cts) (Headers ls a)) = EitherT ServantError IO (Headers ls a)
315+ type Client (Put (ct ': cts) (Headers ls a)) = ExceptT ServantError IO (Headers ls a)
316 clientWithRoute Proxy req baseurl = do
316 clientWithRoute Proxy req baseurl = do
317 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodPut req [200, 201] baseurl
317 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodPut req [200, 201] baseurl
318 return $ Headers { getResponse = resp
318 return $ Headers { getResponse = resp
@@ -328,7 +328,7 @@ instance
328 {-# OVERLAPPABLE #-}
328 {-# OVERLAPPABLE #-}
329#endif
329#endif
330 (MimeUnrender ct a) => HasClient (Patch (ct ': cts) a) where
330 (MimeUnrender ct a) => HasClient (Patch (ct ': cts) a) where
331− type Client (Patch (ct ': cts) a) = EitherT ServantError IO a
331+ type Client (Patch (ct ': cts) a) = ExceptT ServantError IO a
332 clientWithRoute Proxy req baseurl =
332 clientWithRoute Proxy req baseurl =
333 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPatch req [200,201] baseurl
333 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPatch req [200,201] baseurl
334
334
@@ -339,7 +339,7 @@ instance
339 {-# OVERLAPPING #-}
339 {-# OVERLAPPING #-}
340#endif
340#endif
341 HasClient (Patch (ct ': cts) ()) where
341 HasClient (Patch (ct ': cts) ()) where
342− type Client (Patch (ct ': cts) ()) = EitherT ServantError IO ()
342+ type Client (Patch (ct ': cts) ()) = ExceptT ServantError IO ()
343 clientWithRoute Proxy req baseurl =
343 clientWithRoute Proxy req baseurl =
344 void $ performRequestNoBody H.methodPatch req [204] baseurl
344 void $ performRequestNoBody H.methodPatch req [204] baseurl
345
345
@@ -351,7 +351,7 @@ instance
351#endif
351#endif
352 ( MimeUnrender ct a, BuildHeadersTo ls
352 ( MimeUnrender ct a, BuildHeadersTo ls
353 ) => HasClient (Patch (ct ': cts) (Headers ls a)) where
353 ) => HasClient (Patch (ct ': cts) (Headers ls a)) where
354− type Client (Patch (ct ': cts) (Headers ls a)) = EitherT ServantError IO (Headers ls a)
354+ type Client (Patch (ct ': cts) (Headers ls a)) = ExceptT ServantError IO (Headers ls a)
355 clientWithRoute Proxy req baseurl = do
355 clientWithRoute Proxy req baseurl = do
356 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodPatch req [200, 201, 204] baseurl
356 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodPatch req [200, 201, 204] baseurl
357 return $ Headers { getResponse = resp
357 return $ Headers { getResponse = resp
@@ -378,7 +378,7 @@ instance
378-- > myApi :: Proxy MyApi
378-- > myApi :: Proxy MyApi
379-- > myApi = Proxy
379-- > myApi = Proxy
380-- >
380-- >
381−-- > getBooksBy :: Maybe Text -> EitherT String IO [Book]
381+-- > getBooksBy :: Maybe Text -> ExceptT String IO [Book]
382-- > getBooksBy = client myApi host
382-- > getBooksBy = client myApi host
383-- > where host = BaseUrl Http "localhost" 8080
383-- > where host = BaseUrl Http "localhost" 8080
384-- > -- then you can just use "getBooksBy" to query that endpoint.
384-- > -- then you can just use "getBooksBy" to query that endpoint.
@@ -424,7 +424,7 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
424-- > myApi :: Proxy MyApi
424-- > myApi :: Proxy MyApi
425-- > myApi = Proxy
425-- > myApi = Proxy
426-- >
426-- >
427−-- > getBooksBy :: [Text] -> EitherT String IO [Book]
427+-- > getBooksBy :: [Text] -> ExceptT String IO [Book]
428-- > getBooksBy = client myApi host
428-- > getBooksBy = client myApi host
429-- > where host = BaseUrl Http "localhost" 8080
429-- > where host = BaseUrl Http "localhost" 8080
430-- > -- then you can just use "getBooksBy" to query that endpoint.
430-- > -- then you can just use "getBooksBy" to query that endpoint.
@@ -465,7 +465,7 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
465-- > myApi :: Proxy MyApi
465-- > myApi :: Proxy MyApi
466-- > myApi = Proxy
466-- > myApi = Proxy
467-- >
467-- >
468−-- > getBooks :: Bool -> EitherT String IO [Book]
468+-- > getBooks :: Bool -> ExceptT String IO [Book]
469-- > getBooks = client myApi host
469-- > getBooks = client myApi host
470-- > where host = BaseUrl Http "localhost" 8080
470-- > where host = BaseUrl Http "localhost" 8080
471-- > -- then you can just use "getBooks" to query that endpoint.
471-- > -- then you can just use "getBooks" to query that endpoint.
@@ -507,7 +507,7 @@ instance (KnownSymbol sym, HasClient sublayout)
507-- > myApi :: Proxy MyApi
507-- > myApi :: Proxy MyApi
508-- > myApi = Proxy
508-- > myApi = Proxy
509-- >
509-- >
510−-- > getBooksBy :: Maybe Text -> EitherT String IO [Book]
510+-- > getBooksBy :: Maybe Text -> ExceptT String IO [Book]
511-- > getBooksBy = client myApi host
511-- > getBooksBy = client myApi host
512-- > where host = BaseUrl Http "localhost" 8080
512-- > where host = BaseUrl Http "localhost" 8080
513-- > -- then you can just use "getBooksBy" to query that endpoint.
513-- > -- then you can just use "getBooksBy" to query that endpoint.
@@ -552,7 +552,7 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
552-- > myApi :: Proxy MyApi
552-- > myApi :: Proxy MyApi
553-- > myApi = Proxy
553-- > myApi = Proxy
554-- >
554-- >
555−-- > getBooksBy :: [Text] -> EitherT String IO [Book]
555+-- > getBooksBy :: [Text] -> ExceptT String IO [Book]
556-- > getBooksBy = client myApi host
556-- > getBooksBy = client myApi host
557-- > where host = BaseUrl Http "localhost" 8080
557-- > where host = BaseUrl Http "localhost" 8080
558-- > -- then you can just use "getBooksBy" to query that endpoint.
558-- > -- then you can just use "getBooksBy" to query that endpoint.
@@ -593,7 +593,7 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
593-- > myApi :: Proxy MyApi
593-- > myApi :: Proxy MyApi
594-- > myApi = Proxy
594-- > myApi = Proxy
595-- >
595-- >
596−-- > getBooks :: Bool -> EitherT String IO [Book]
596+-- > getBooks :: Bool -> ExceptT String IO [Book]
597-- > getBooks = client myApi host
597-- > getBooks = client myApi host
598-- > where host = BaseUrl Http "localhost" 8080
598-- > where host = BaseUrl Http "localhost" 8080
599-- > -- then you can just use "getBooks" to query that endpoint.
599-- > -- then you can just use "getBooks" to query that endpoint.
@@ -618,7 +618,7 @@ instance (KnownSymbol sym, HasClient sublayout)
618-- | Pick a 'Method' and specify where the server you want to query is. You get
618-- | Pick a 'Method' and specify where the server you want to query is. You get
619-- back the full `Response`.
619-- back the full `Response`.
620instance HasClient Raw where
620instance HasClient Raw where
621− type Client Raw = H.Method -> EitherT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], Response ByteString)
621+ type Client Raw = H.Method -> ExceptT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], Response ByteString)
622
622
623 clientWithRoute :: Proxy Raw -> Req -> BaseUrl -> Client Raw
623 clientWithRoute :: Proxy Raw -> Req -> BaseUrl -> Client Raw
624 clientWithRoute Proxy req baseurl httpMethod = do
624 clientWithRoute Proxy req baseurl httpMethod = do
@@ -639,7 +639,7 @@ instance HasClient Raw where
639-- > myApi :: Proxy MyApi
639-- > myApi :: Proxy MyApi
640-- > myApi = Proxy
640-- > myApi = Proxy
641-- >
641-- >
642−-- > addBook :: Book -> EitherT String IO Book
642+-- > addBook :: Book -> ExceptT String IO Book
643-- > addBook = client myApi host
643-- > addBook = client myApi host
644-- > where host = BaseUrl Http "localhost" 8080
644-- > where host = BaseUrl Http "localhost" 8080
645-- > -- then you can just use "addBook" to query that endpoint
645-- > -- then you can just use "addBook" to query that endpoint
servant-client/src/Servant/Common/Req.hs+9−9
@@ -11,7 +11,7 @@ import Control.Exception
11import Control.Monad
11import Control.Monad
12import Control.Monad.Catch (MonadThrow)
12import Control.Monad.Catch (MonadThrow)
13import Control.Monad.IO.Class
13import Control.Monad.IO.Class
14−import Control.Monad.Trans.Either
14+import Control.Monad.Trans.Except
15import Data.ByteString.Lazy hiding (pack, filter, map, null, elem)
15import Data.ByteString.Lazy hiding (pack, filter, map, null, elem)
16import Data.IORef
16import Data.IORef
17import Data.String
17import Data.String
@@ -142,7 +142,7 @@ displayHttpRequest httpmethod = "HTTP " ++ cs httpmethod ++ " request"
142
142
143
143
144performRequest :: Method -> Req -> (Int -> Bool) -> BaseUrl
144performRequest :: Method -> Req -> (Int -> Bool) -> BaseUrl
145− -> EitherT ServantError IO ( Int, ByteString, MediaType
145+ -> ExceptT ServantError IO ( Int, ByteString, MediaType
146 , [HTTP.Header], Response ByteString)
146 , [HTTP.Header], Response ByteString)
147performRequest reqMethod req isWantedStatus reqHost = do
147performRequest reqMethod req isWantedStatus reqHost = do
148 partialRequest <- liftIO $ reqToRequest req reqHost
148 partialRequest <- liftIO $ reqToRequest req reqHost
@@ -156,7 +156,7 @@ performRequest reqMethod req isWantedStatus reqHost = do
156 Client.httpLbs request manager
156 Client.httpLbs request manager
157 case eResponse of
157 case eResponse of
158 Left err ->
158 Left err ->
159− left . ConnectionError $ SomeException err
159+ throwE . ConnectionError $ SomeException err
160
160
161 Right response -> do
161 Right response -> do
162 let status = Client.responseStatus response
162 let status = Client.responseStatus response
@@ -166,25 +166,25 @@ performRequest reqMethod req isWantedStatus reqHost = do
166 ct <- case lookup "Content-Type" $ Client.responseHeaders response of
166 ct <- case lookup "Content-Type" $ Client.responseHeaders response of
167 Nothing -> pure $ "application"//"octet-stream"
167 Nothing -> pure $ "application"//"octet-stream"
168 Just t -> case parseAccept t of
168 Just t -> case parseAccept t of
169− Nothing -> left $ InvalidContentTypeHeader (cs t) body
169+ Nothing -> throwE $ InvalidContentTypeHeader (cs t) body
170 Just t' -> pure t'
170 Just t' -> pure t'
171 unless (isWantedStatus status_code) $
171 unless (isWantedStatus status_code) $
172− left $ FailureResponse status ct body
172+ throwE $ FailureResponse status ct body
173 return (status_code, body, ct, hrds, response)
173 return (status_code, body, ct, hrds, response)
174
174
175
175
176performRequestCT :: MimeUnrender ct result =>
176performRequestCT :: MimeUnrender ct result =>
177− Proxy ct -> Method -> Req -> [Int] -> BaseUrl -> EitherT ServantError IO ([HTTP.Header], result)
177+ Proxy ct -> Method -> Req -> [Int] -> BaseUrl -> ExceptT ServantError IO ([HTTP.Header], result)
178performRequestCT ct reqMethod req wantedStatus reqHost = do
178performRequestCT ct reqMethod req wantedStatus reqHost = do
179 let acceptCT = contentType ct
179 let acceptCT = contentType ct
180 (_status, respBody, respCT, hrds, _response) <-
180 (_status, respBody, respCT, hrds, _response) <-
181 performRequest reqMethod (req { reqAccept = [acceptCT] }) (`elem` wantedStatus) reqHost
181 performRequest reqMethod (req { reqAccept = [acceptCT] }) (`elem` wantedStatus) reqHost
182− unless (matches respCT (acceptCT)) $ left $ UnsupportedContentType respCT respBody
182+ unless (matches respCT (acceptCT)) $ throwE $ UnsupportedContentType respCT respBody
183 case mimeUnrender ct respBody of
183 case mimeUnrender ct respBody of
184− Left err -> left $ DecodeFailure err respCT respBody
184+ Left err -> throwE $ DecodeFailure err respCT respBody
185 Right val -> return (hrds, val)
185 Right val -> return (hrds, val)
186
186
187−performRequestNoBody :: Method -> Req -> [Int] -> BaseUrl -> EitherT ServantError IO ()
187+performRequestNoBody :: Method -> Req -> [Int] -> BaseUrl -> ExceptT ServantError IO ()
188performRequestNoBody reqMethod req wantedStatus reqHost = do
188performRequestNoBody reqMethod req wantedStatus reqHost = do
189 _ <- performRequest reqMethod req (`elem` wantedStatus) reqHost
189 _ <- performRequest reqMethod req (`elem` wantedStatus) reqHost
190 return ()
190 return ()
servant-client/test/Servant/ClientSpec.hs+56−56
@@ -13,12 +13,12 @@
13module Servant.ClientSpec where
13module Servant.ClientSpec where
14
14
15#if !MIN_VERSION_base(4,8,0)
15#if !MIN_VERSION_base(4,8,0)
16−import Control.Applicative ((<$>))
16+import Control.Applicative ((<$>))
17#endif
17#endif
18−import qualified Control.Arrow as Arrow
18+import Control.Arrow (left)
19import Control.Concurrent
19import Control.Concurrent
20import Control.Exception
20import Control.Exception
21−import Control.Monad.Trans.Either
21+import Control.Monad.Trans.Except
22import Data.Aeson
22import Data.Aeson
23import Data.ByteString.Lazy (ByteString)
23import Data.ByteString.Lazy (ByteString)
24import Data.Char
24import Data.Char
@@ -105,14 +105,14 @@ server = serve api (
105 :<|> return
105 :<|> return
106 :<|> (\ name -> case name of
106 :<|> (\ name -> case name of
107 Just "alice" -> return alice
107 Just "alice" -> return alice
108− Just name -> left $ ServantErr 400 (name ++ " not found") "" []
108+ Just name -> throwE $ ServantErr 400 (name ++ " not found") "" []
109− Nothing -> left $ ServantErr 400 "missing parameter" "" [])
109+ Nothing -> throwE $ ServantErr 400 "missing parameter" "" [])
110 :<|> (\ names -> return (zipWith Person names [0..]))
110 :<|> (\ names -> return (zipWith Person names [0..]))
111 :<|> return
111 :<|> return
112 :<|> (\ name -> case name of
112 :<|> (\ name -> case name of
113 Just "alice" -> return alice
113 Just "alice" -> return alice
114− Just name -> left $ ServantErr 400 (name ++ " not found") "" []
114+ Just name -> throwE $ ServantErr 400 (name ++ " not found") "" []
115− Nothing -> left $ ServantErr 400 "missing parameter" "" [])
115+ Nothing -> throwE $ ServantErr 400 "missing parameter" "" [])
116 :<|> (\ names -> return (zipWith Person names [0..]))
116 :<|> (\ names -> return (zipWith Person names [0..]))
117 :<|> return
117 :<|> return
118 :<|> (\ _request respond -> respond $ responseLBS ok200 [] "rawSuccess")
118 :<|> (\ _request respond -> respond $ responseLBS ok200 [] "rawSuccess")
@@ -144,21 +144,21 @@ withFailServer action = withWaiDaemon (return failServer) action
144
144
145spec :: IO ()
145spec :: IO ()
146spec = withServer $ \ baseUrl -> do
146spec = withServer $ \ baseUrl -> do
147− let getGet :: EitherT ServantError IO Person
147+ let getGet :: ExceptT ServantError IO Person
148− getDeleteEmpty :: EitherT ServantError IO ()
148+ getDeleteEmpty :: ExceptT ServantError IO ()
149− getCapture :: String -> EitherT ServantError IO Person
149+ getCapture :: String -> ExceptT ServantError IO Person
150− getBody :: Person -> EitherT ServantError IO Person
150+ getBody :: Person -> ExceptT ServantError IO Person
151− getQueryParam :: Maybe String -> EitherT ServantError IO Person
151+ getQueryParam :: Maybe String -> ExceptT ServantError IO Person
152− getQueryParams :: [String] -> EitherT ServantError IO [Person]
152+ getQueryParams :: [String] -> ExceptT ServantError IO [Person]
153− getQueryFlag :: Bool -> EitherT ServantError IO Bool
153+ getQueryFlag :: Bool -> ExceptT ServantError IO Bool
154− getMatrixParam :: Maybe String -> EitherT ServantError IO Person
154+ getMatrixParam :: Maybe String -> ExceptT ServantError IO Person
155− getMatrixParams :: [String] -> EitherT ServantError IO [Person]
155+ getMatrixParams :: [String] -> ExceptT ServantError IO [Person]
156− getMatrixFlag :: Bool -> EitherT ServantError IO Bool
156+ getMatrixFlag :: Bool -> ExceptT ServantError IO Bool
157− getRawSuccess :: Method -> EitherT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], C.Response ByteString)
157+ getRawSuccess :: Method -> ExceptT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], C.Response ByteString)
158− getRawFailure :: Method -> EitherT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], C.Response ByteString)
158+ getRawFailure :: Method -> ExceptT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], C.Response ByteString)
159− getMultiple :: String -> Maybe Int -> Bool -> [(String, [Rational])] -> EitherT ServantError IO (String, Maybe Int, Bool, [(String, [Rational])])
159+ getMultiple :: String -> Maybe Int -> Bool -> [(String, [Rational])] -> ExceptT ServantError IO (String, Maybe Int, Bool, [(String, [Rational])])
160− getRespHeaders :: EitherT ServantError IO (Headers TestHeaders Bool)
160+ getRespHeaders :: ExceptT ServantError IO (Headers TestHeaders Bool)
161− getDeleteContentType :: EitherT ServantError IO ()
161+ getDeleteContentType :: ExceptT ServantError IO ()
162 ( getGet
162 ( getGet
163 :<|> getDeleteEmpty
163 :<|> getDeleteEmpty
164 :<|> getCapture
164 :<|> getCapture
@@ -178,54 +178,54 @@ spec = withServer $ \ baseUrl -> do
178
178
179 hspec $ do
179 hspec $ do
180 it "Servant.API.Get" $ do
180 it "Servant.API.Get" $ do
181− (Arrow.left show <$> runEitherT getGet) `shouldReturn` Right alice
181+ (left show <$> runExceptT getGet) `shouldReturn` Right alice
182
182
183 describe "Servant.API.Delete" $ do
183 describe "Servant.API.Delete" $ do
184 it "allows empty content type" $ do
184 it "allows empty content type" $ do
185− (Arrow.left show <$> runEitherT getDeleteEmpty) `shouldReturn` Right ()
185+ (left show <$> runExceptT getDeleteEmpty) `shouldReturn` Right ()
186
186
187 it "allows content type" $ do
187 it "allows content type" $ do
188− (Arrow.left show <$> runEitherT getDeleteContentType) `shouldReturn` Right ()
188+ (left show <$> runExceptT getDeleteContentType) `shouldReturn` Right ()
189
189
190 it "Servant.API.Capture" $ do
190 it "Servant.API.Capture" $ do
191− (Arrow.left show <$> runEitherT (getCapture "Paula")) `shouldReturn` Right (Person "Paula" 0)
191+ (left show <$> runExceptT (getCapture "Paula")) `shouldReturn` Right (Person "Paula" 0)
192
192
193 it "Servant.API.ReqBody" $ do
193 it "Servant.API.ReqBody" $ do
194 let p = Person "Clara" 42
194 let p = Person "Clara" 42
195− (Arrow.left show <$> runEitherT (getBody p)) `shouldReturn` Right p
195+ (left show <$> runExceptT (getBody p)) `shouldReturn` Right p
196
196
197 it "Servant.API.QueryParam" $ do
197 it "Servant.API.QueryParam" $ do
198− Arrow.left show <$> runEitherT (getQueryParam (Just "alice")) `shouldReturn` Right alice
198+ left show <$> runExceptT (getQueryParam (Just "alice")) `shouldReturn` Right alice
199− Left FailureResponse{..} <- runEitherT (getQueryParam (Just "bob"))
199+ Left FailureResponse{..} <- runExceptT (getQueryParam (Just "bob"))
200 responseStatus `shouldBe` Status 400 "bob not found"
200 responseStatus `shouldBe` Status 400 "bob not found"
201
201
202 it "Servant.API.QueryParam.QueryParams" $ do
202 it "Servant.API.QueryParam.QueryParams" $ do
203− (Arrow.left show <$> runEitherT (getQueryParams [])) `shouldReturn` Right []
203+ (left show <$> runExceptT (getQueryParams [])) `shouldReturn` Right []
204− (Arrow.left show <$> runEitherT (getQueryParams ["alice", "bob"]))
204+ (left show <$> runExceptT (getQueryParams ["alice", "bob"]))
205 `shouldReturn` Right [Person "alice" 0, Person "bob" 1]
205 `shouldReturn` Right [Person "alice" 0, Person "bob" 1]
206
206
207 context "Servant.API.QueryParam.QueryFlag" $
207 context "Servant.API.QueryParam.QueryFlag" $
208 forM_ [False, True] $ \ flag ->
208 forM_ [False, True] $ \ flag ->
209 it (show flag) $ do
209 it (show flag) $ do
210− (Arrow.left show <$> runEitherT (getQueryFlag flag)) `shouldReturn` Right flag
210+ (left show <$> runExceptT (getQueryFlag flag)) `shouldReturn` Right flag
211
211
212 it "Servant.API.MatrixParam" $ do
212 it "Servant.API.MatrixParam" $ do
213− Arrow.left show <$> runEitherT (getMatrixParam (Just "alice")) `shouldReturn` Right alice
213+ left show <$> runExceptT (getMatrixParam (Just "alice")) `shouldReturn` Right alice
214− Left FailureResponse{..} <- runEitherT (getMatrixParam (Just "bob"))
214+ Left FailureResponse{..} <- runExceptT (getMatrixParam (Just "bob"))
215 responseStatus `shouldBe` Status 400 "bob not found"
215 responseStatus `shouldBe` Status 400 "bob not found"
216
216
217 it "Servant.API.MatrixParam.MatrixParams" $ do
217 it "Servant.API.MatrixParam.MatrixParams" $ do
218− Arrow.left show <$> runEitherT (getMatrixParams []) `shouldReturn` Right []
218+ left show <$> runExceptT (getMatrixParams []) `shouldReturn` Right []
219− Arrow.left show <$> runEitherT (getMatrixParams ["alice", "bob"])
219+ left show <$> runExceptT (getMatrixParams ["alice", "bob"])
220 `shouldReturn` Right [Person "alice" 0, Person "bob" 1]
220 `shouldReturn` Right [Person "alice" 0, Person "bob" 1]
221
221
222 context "Servant.API.MatrixParam.MatrixFlag" $
222 context "Servant.API.MatrixParam.MatrixFlag" $
223 forM_ [False, True] $ \ flag ->
223 forM_ [False, True] $ \ flag ->
224 it (show flag) $ do
224 it (show flag) $ do
225− Arrow.left show <$> runEitherT (getMatrixFlag flag) `shouldReturn` Right flag
225+ left show <$> runExceptT (getMatrixFlag flag) `shouldReturn` Right flag
226
226
227 it "Servant.API.Raw on success" $ do
227 it "Servant.API.Raw on success" $ do
228− res <- runEitherT (getRawSuccess methodGet)
228+ res <- runExceptT (getRawSuccess methodGet)
229 case res of
229 case res of
230 Left e -> assertFailure $ show e
230 Left e -> assertFailure $ show e
231 Right (code, body, ct, _, response) -> do
231 Right (code, body, ct, _, response) -> do
@@ -234,7 +234,7 @@ spec = withServer $ \ baseUrl -> do
234 C.responseStatus response `shouldBe` ok200
234 C.responseStatus response `shouldBe` ok200
235
235
236 it "Servant.API.Raw on failure" $ do
236 it "Servant.API.Raw on failure" $ do
237− res <- runEitherT (getRawFailure methodGet)
237+ res <- runExceptT (getRawFailure methodGet)
238 case res of
238 case res of
239 Left e -> assertFailure $ show e
239 Left e -> assertFailure $ show e
240 Right (code, body, ct, _, response) -> do
240 Right (code, body, ct, _, response) -> do
@@ -243,7 +243,7 @@ spec = withServer $ \ baseUrl -> do
243 C.responseStatus response `shouldBe` badRequest400
243 C.responseStatus response `shouldBe` badRequest400
244
244
245 it "Returns headers appropriately" $ withServer $ \ _ -> do
245 it "Returns headers appropriately" $ withServer $ \ _ -> do
246− res <- runEitherT getRespHeaders
246+ res <- runExceptT getRespHeaders
247 case res of
247 case res of
248 Left e -> assertFailure $ show e
248 Left e -> assertFailure $ show e
249 Right val -> getHeaders val `shouldBe` [("X-Example1", "1729"), ("X-Example2", "eg2")]
249 Right val -> getHeaders val `shouldBe` [("X-Example1", "1729"), ("X-Example2", "eg2")]
@@ -252,7 +252,7 @@ spec = withServer $ \ baseUrl -> do
252 it "works for a combination of Capture, QueryParam, QueryFlag and ReqBody" $
252 it "works for a combination of Capture, QueryParam, QueryFlag and ReqBody" $
253 property $ forAllShrink pathGen shrink $ \(NonEmpty cap) num flag body ->
253 property $ forAllShrink pathGen shrink $ \(NonEmpty cap) num flag body ->
254 ioProperty $ do
254 ioProperty $ do
255− result <- Arrow.left show <$> runEitherT (getMultiple cap num flag body)
255+ result <- left show <$> runExceptT (getMultiple cap num flag body)
256 return $
256 return $
257 result === Right (cap, num, flag, body)
257 result === Right (cap, num, flag, body)
258
258
@@ -261,11 +261,11 @@ spec = withServer $ \ baseUrl -> do
261 let test :: (WrappedApi, String) -> Spec
261 let test :: (WrappedApi, String) -> Spec
262 test (WrappedApi api, desc) =
262 test (WrappedApi api, desc) =
263 it desc $
263 it desc $
264− withWaiDaemon (return (serve api (left $ ServantErr 500 "error message" "" []))) $
264+ withWaiDaemon (return (serve api (throwE $ ServantErr 500 "error message" "" []))) $
265 \ host -> do
265 \ host -> do
266− let getResponse :: EitherT ServantError IO ()
266+ let getResponse :: ExceptT ServantError IO ()
267 getResponse = client api host
267 getResponse = client api host
268− Left FailureResponse{..} <- runEitherT getResponse
268+ Left FailureResponse{..} <- runExceptT getResponse
269 responseStatus `shouldBe` (Status 500 "error message")
269 responseStatus `shouldBe` (Status 500 "error message")
270 mapM_ test $
270 mapM_ test $
271 (WrappedApi (Proxy :: Proxy (Delete '[JSON] ())), "Delete") :
271 (WrappedApi (Proxy :: Proxy (Delete '[JSON] ())), "Delete") :
@@ -276,54 +276,54 @@ spec = withServer $ \ baseUrl -> do
276
276
277failSpec :: IO ()
277failSpec :: IO ()
278failSpec = withFailServer $ \ baseUrl -> do
278failSpec = withFailServer $ \ baseUrl -> do
279− let getGet :: EitherT ServantError IO Person
279+ let getGet :: ExceptT ServantError IO Person
280− getDeleteEmpty :: EitherT ServantError IO ()
280+ getDeleteEmpty :: ExceptT ServantError IO ()
281− getCapture :: String -> EitherT ServantError IO Person
281+ getCapture :: String -> ExceptT ServantError IO Person
282− getBody :: Person -> EitherT ServantError IO Person
282+ getBody :: Person -> ExceptT ServantError IO Person
283 ( getGet
283 ( getGet
284 :<|> getDeleteEmpty
284 :<|> getDeleteEmpty
285 :<|> getCapture
285 :<|> getCapture
286 :<|> getBody
286 :<|> getBody
287 :<|> _ )
287 :<|> _ )
288 = client api baseUrl
288 = client api baseUrl
289− getGetWrongHost :: EitherT ServantError IO Person
289+ getGetWrongHost :: ExceptT ServantError IO Person
290 (getGetWrongHost :<|> _) = client api (BaseUrl Http "127.0.0.1" 19872 "")
290 (getGetWrongHost :<|> _) = client api (BaseUrl Http "127.0.0.1" 19872 "")
291
291
292 hspec $ do
292 hspec $ do
293 context "client returns errors appropriately" $ do
293 context "client returns errors appropriately" $ do
294 it "reports FailureResponse" $ do
294 it "reports FailureResponse" $ do
295− Left res <- runEitherT getDeleteEmpty
295+ Left res <- runExceptT getDeleteEmpty
296 case res of
296 case res of
297 FailureResponse (Status 404 "Not Found") _ _ -> return ()
297 FailureResponse (Status 404 "Not Found") _ _ -> return ()
298 _ -> fail $ "expected 404 response, but got " <> show res
298 _ -> fail $ "expected 404 response, but got " <> show res
299
299
300 it "reports DecodeFailure" $ do
300 it "reports DecodeFailure" $ do
301− Left res <- runEitherT (getCapture "foo")
301+ Left res <- runExceptT (getCapture "foo")
302 case res of
302 case res of
303 DecodeFailure _ ("application/json") _ -> return ()
303 DecodeFailure _ ("application/json") _ -> return ()
304 _ -> fail $ "expected DecodeFailure, but got " <> show res
304 _ -> fail $ "expected DecodeFailure, but got " <> show res
305
305
306 it "reports ConnectionError" $ do
306 it "reports ConnectionError" $ do
307− Left res <- runEitherT getGetWrongHost
307+ Left res <- runExceptT getGetWrongHost
308 case res of
308 case res of
309 ConnectionError _ -> return ()
309 ConnectionError _ -> return ()
310 _ -> fail $ "expected ConnectionError, but got " <> show res
310 _ -> fail $ "expected ConnectionError, but got " <> show res
311
311
312 it "reports UnsupportedContentType" $ do
312 it "reports UnsupportedContentType" $ do
313− Left res <- runEitherT getGet
313+ Left res <- runExceptT getGet
314 case res of
314 case res of
315 UnsupportedContentType ("application/octet-stream") _ -> return ()
315 UnsupportedContentType ("application/octet-stream") _ -> return ()
316 _ -> fail $ "expected UnsupportedContentType, but got " <> show res
316 _ -> fail $ "expected UnsupportedContentType, but got " <> show res
317
317
318 it "reports InvalidContentTypeHeader" $ do
318 it "reports InvalidContentTypeHeader" $ do
319− Left res <- runEitherT (getBody alice)
319+ Left res <- runExceptT (getBody alice)
320 case res of
320 case res of
321 InvalidContentTypeHeader "fooooo" _ -> return ()
321 InvalidContentTypeHeader "fooooo" _ -> return ()
322 _ -> fail $ "expected InvalidContentTypeHeader, but got " <> show res
322 _ -> fail $ "expected InvalidContentTypeHeader, but got " <> show res
323
323
324data WrappedApi where
324data WrappedApi where
325− WrappedApi :: (HasServer api, Server api ~ EitherT ServantErr IO a,
325+ WrappedApi :: (HasServer api, Server api ~ ExceptT ServantErr IO a,
326− HasClient api, Client api ~ EitherT ServantError IO ()) =>
326+ HasClient api, Client api ~ ExceptT ServantError IO ()) =>
327 Proxy api -> WrappedApi
327 Proxy api -> WrappedApi
328
328
329
329
servant-examples/hackage/hackage.hs+5−5
@@ -5,7 +5,7 @@
5import Control.Applicative
5import Control.Applicative
6import Control.Monad
6import Control.Monad
7import Control.Monad.IO.Class
7import Control.Monad.IO.Class
8−import Control.Monad.Trans.Either
8+import Control.Monad.Trans.Except
9import Data.Aeson
9import Data.Aeson
10import Data.Monoid
10import Data.Monoid
11import Data.Proxy
11import Data.Proxy
@@ -54,16 +54,16 @@ instance FromJSON Package
54hackageAPI :: Proxy HackageAPI
54hackageAPI :: Proxy HackageAPI
55hackageAPI = Proxy
55hackageAPI = Proxy
56
56
57−getUsers :: EitherT ServantError IO [UserSummary]
57+getUsers :: ExceptT ServantError IO [UserSummary]
58−getUser :: Username -> EitherT ServantError IO UserDetailed
58+getUser :: Username -> ExceptT ServantError IO UserDetailed
59−getPackages :: EitherT ServantError IO [Package]
59+getPackages :: ExceptT ServantError IO [Package]
60getUsers :<|> getUser :<|> getPackages = client hackageAPI $ BaseUrl Http "hackage.haskell.org" 80 ""
60getUsers :<|> getUser :<|> getPackages = client hackageAPI $ BaseUrl Http "hackage.haskell.org" 80 ""
61
61
62main :: IO ()
62main :: IO ()
63main = print =<< uselessNumbers
63main = print =<< uselessNumbers
64
64
65uselessNumbers :: IO (Either ServantError ())
65uselessNumbers :: IO (Either ServantError ())
66−uselessNumbers = runEitherT $ do
66+uselessNumbers = runExceptT $ do
67 users <- getUsers
67 users <- getUsers
68 liftIO . putStrLn $ show (length users) ++ " users"
68 liftIO . putStrLn $ show (length users) ++ " users"
69
69
servant-examples/servant-examples.cabal+1−3
@@ -25,7 +25,6 @@ executable tutorial
25 , base >= 4.7 && < 5
25 , base >= 4.7 && < 5
26 , bytestring
26 , bytestring
27 , directory
27 , directory
28− , either
29 , http-types
28 , http-types
30 , js-jquery
29 , js-jquery
31 , lucid
30 , lucid
@@ -50,10 +49,10 @@ executable t8-main
50 build-depends:
49 build-depends:
51 aeson
50 aeson
52 , base >= 4.7 && < 5
51 , base >= 4.7 && < 5
53− , either
54 , servant == 0.5.*
52 , servant == 0.5.*
55 , servant-client == 0.5.*
53 , servant-client == 0.5.*
56 , servant-server == 0.5.*
54 , servant-server == 0.5.*
55+ , transformers
57 , wai
56 , wai
58
57
59executable hackage
58executable hackage
@@ -61,7 +60,6 @@ executable hackage
61 build-depends:
60 build-depends:
62 aeson >= 0.8
61 aeson >= 0.8
63 , base >=4.7 && < 5
62 , base >=4.7 && < 5
64− , either
65 , servant == 0.5.*
63 , servant == 0.5.*
66 , servant-client == 0.5.*
64 , servant-client == 0.5.*
67 , text
65 , text
servant-examples/tutorial/T3.hs+4−4
@@ -4,7 +4,7 @@
4{-# LANGUAGE TypeOperators #-}
4{-# LANGUAGE TypeOperators #-}
5module T3 where
5module T3 where
6
6
7−import Control.Monad.Trans.Either
7+import Control.Monad.Trans.Except
8import Data.Aeson
8import Data.Aeson
9import Data.List
9import Data.List
10import GHC.Generics
10import GHC.Generics
@@ -69,15 +69,15 @@ server = position
69 :<|> hello
69 :<|> hello
70 :<|> marketing
70 :<|> marketing
71
71
72− where position :: Int -> Int -> EitherT ServantErr IO Position
72+ where position :: Int -> Int -> ExceptT ServantErr IO Position
73 position x y = return (Position x y)
73 position x y = return (Position x y)
74
74
75− hello :: Maybe String -> EitherT ServantErr IO HelloMessage
75+ hello :: Maybe String -> ExceptT ServantErr IO HelloMessage
76 hello mname = return . HelloMessage $ case mname of
76 hello mname = return . HelloMessage $ case mname of
77 Nothing -> "Hello, anonymous coward"
77 Nothing -> "Hello, anonymous coward"
78 Just n -> "Hello, " ++ n
78 Just n -> "Hello, " ++ n
79
79
80− marketing :: ClientInfo -> EitherT ServantErr IO Email
80+ marketing :: ClientInfo -> ExceptT ServantErr IO Email
81 marketing clientinfo = return (emailForClient clientinfo)
81 marketing clientinfo = return (emailForClient clientinfo)
82
82
83app :: Application
83app :: Application
servant-examples/tutorial/T5.hs+2−2
@@ -6,7 +6,7 @@
6module T5 where
6module T5 where
7
7
8import Control.Monad.IO.Class
8import Control.Monad.IO.Class
9−import Control.Monad.Trans.Either
9+import Control.Monad.Trans.Except
10import Data.Aeson
10import Data.Aeson
11import GHC.Generics
11import GHC.Generics
12import Network.Wai
12import Network.Wai
@@ -29,7 +29,7 @@ server = do
29 exists <- liftIO (doesFileExist "myfile.txt")
29 exists <- liftIO (doesFileExist "myfile.txt")
30 if exists
30 if exists
31 then liftIO (readFile "myfile.txt") >>= return . FileContent
31 then liftIO (readFile "myfile.txt") >>= return . FileContent
32− else left custom404Err
32+ else throwE custom404Err
33
33
34 where custom404Err = err404 { errBody = "myfile.txt just isn't there, please leave this server alone." }
34 where custom404Err = err404 { errBody = "myfile.txt just isn't there, please leave this server alone." }
35
35
servant-examples/tutorial/T7.hs+2−2
@@ -3,7 +3,7 @@
3{-# LANGUAGE TypeOperators #-}
3{-# LANGUAGE TypeOperators #-}
4module T7 where
4module T7 where
5
5
6−import Control.Monad.Trans.Either
6+import Control.Monad.Trans.Except
7import Control.Monad.Trans.Reader
7import Control.Monad.Trans.Reader
8import Network.Wai
8import Network.Wai
9import Servant
9import Servant
@@ -26,7 +26,7 @@ readerServerT = a :<|> b
26readerServer :: Server ReaderAPI
26readerServer :: Server ReaderAPI
27readerServer = enter readerToEither readerServerT
27readerServer = enter readerToEither readerServerT
28
28
29− where readerToEither :: Reader String :~> EitherT ServantErr IO
29+ where readerToEither :: Reader String :~> ExceptT ServantErr IO
30 readerToEither = Nat $ \r -> return (runReader r "hi")
30 readerToEither = Nat $ \r -> return (runReader r "hi")
31
31
32app :: Application
32app :: Application
servant-examples/tutorial/T8.hs+6−6
@@ -3,7 +3,7 @@
3{-# LANGUAGE TypeOperators #-}
3{-# LANGUAGE TypeOperators #-}
4module T8 where
4module T8 where
5
5
6−import Control.Monad.Trans.Either
6+import Control.Monad.Trans.Except
7import Data.Aeson
7import Data.Aeson
8import Servant
8import Servant
9import Servant.Client
9import Servant.Client
@@ -12,20 +12,20 @@ import T3
12
12
13position :: Int -- ^ value for "x"
13position :: Int -- ^ value for "x"
14 -> Int -- ^ value for "y"
14 -> Int -- ^ value for "y"
15− -> EitherT ServantError IO Position
15+ -> ExceptT ServantError IO Position
16
16
17hello :: Maybe String -- ^ an optional value for "name"
17hello :: Maybe String -- ^ an optional value for "name"
18− -> EitherT ServantError IO HelloMessage
18+ -> ExceptT ServantError IO HelloMessage
19
19
20marketing :: ClientInfo -- ^ value for the request body
20marketing :: ClientInfo -- ^ value for the request body
21− -> EitherT ServantError IO Email
21+ -> ExceptT ServantError IO Email
22
22
23position :<|> hello :<|> marketing = client api baseUrl
23position :<|> hello :<|> marketing = client api baseUrl
24
24
25baseUrl :: BaseUrl
25baseUrl :: BaseUrl
26baseUrl = BaseUrl Http "localhost" 8081 ""
26baseUrl = BaseUrl Http "localhost" 8081 ""
27
27
28−queries :: EitherT ServantError IO (Position, HelloMessage, Email)
28+queries :: ExceptT ServantError IO (Position, HelloMessage, Email)
29queries = do
29queries = do
30 pos <- position 10 10
30 pos <- position 10 10
31 msg <- hello (Just "servant")
31 msg <- hello (Just "servant")
@@ -34,7 +34,7 @@ queries = do
34
34
35run :: IO ()
35run :: IO ()
36run = do
36run = do
37− res <- runEitherT queries
37+ res <- runExceptT queries
38 case res of
38 case res of
39 Left err -> putStrLn $ "Error: " ++ show err
39 Left err -> putStrLn $ "Error: " ++ show err
40 Right (pos, msg, em) -> do
40 Right (pos, msg, em) -> do
servant-mock/src/Servant/Mock.hs+2−2
@@ -91,8 +91,8 @@ class HasServer api => HasMock api where
91 -- actually "means" 2 request handlers, of the following types:
91 -- actually "means" 2 request handlers, of the following types:
92 --
92 --
93 -- @
93 -- @
94− -- getUser :: EitherT ServantErr IO User
94+ -- getUser :: ExceptT ServantErr IO User
95− -- getBook :: EitherT ServantErr IO Book
95+ -- getBook :: ExceptT ServantErr IO Book
96 -- @
96 -- @
97 --
97 --
98 -- So under the hood, 'mock' uses the 'IO' bit to generate
98 -- So under the hood, 'mock' uses the 'IO' bit to generate
servant-server/CHANGELOG.md+1
@@ -2,6 +2,7 @@ HEAD
2----
2----
3
3
4* Support for the `HttpVersion`, `IsSecure`, `RemoteHost` and `Vault` combinators
4* Support for the `HttpVersion`, `IsSecure`, `RemoteHost` and `Vault` combinators
5+* Drop `EitherT` in favor of `ExceptT`
5
6
60.4.1
70.4.1
7-----
8-----
servant-server/example/greet.hs+1−1
@@ -44,7 +44,7 @@ testApi = Proxy
44-- There's one handler per endpoint, which, just like in the type
44-- There's one handler per endpoint, which, just like in the type
45-- that represents the API, are glued together using :<|>.
45-- that represents the API, are glued together using :<|>.
46--
46--
47−-- Each handler runs in the 'EitherT ServantErr IO' monad.
47+-- Each handler runs in the 'ExceptT ServantErr IO' monad.
48server :: Server TestApi
48server :: Server TestApi
49server = helloH :<|> postGreetH :<|> deleteGreetH
49server = helloH :<|> postGreetH :<|> deleteGreetH
50
50
servant-server/servant-server.cabal−2
@@ -48,7 +48,6 @@ library
48 , attoparsec >= 0.12 && < 0.14
48 , attoparsec >= 0.12 && < 0.14
49 , bytestring >= 0.10 && < 0.11
49 , bytestring >= 0.10 && < 0.11
50 , containers >= 0.5 && < 0.6
50 , containers >= 0.5 && < 0.6
51− , either >= 4.3 && < 4.5
52 , http-types >= 0.8 && < 0.9
51 , http-types >= 0.8 && < 0.9
53 , network-uri >= 2.6 && < 2.7
52 , network-uri >= 2.6 && < 2.7
54 , mtl >= 2 && < 3
53 , mtl >= 2 && < 3
@@ -97,7 +96,6 @@ test-suite spec
97 , bytestring
96 , bytestring
98 , bytestring-conversion
97 , bytestring-conversion
99 , directory
98 , directory
100− , either
101 , exceptions
99 , exceptions
102 , hspec == 2.*
100 , hspec == 2.*
103 , hspec-wai
101 , hspec-wai
servant-server/src/Servant/Server.hs+1−5
@@ -1,4 +1,3 @@
1−{-# LANGUAGE CPP #-}
2{-# LANGUAGE FlexibleContexts #-}
1{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE TypeFamilies #-}
3{-# LANGUAGE TypeFamilies #-}
@@ -29,9 +28,6 @@ module Servant.Server
29 , evalStateTSNat
28 , evalStateTSNat
30 , logWriterTLNat
29 , logWriterTLNat
31 , logWriterTSNat
30 , logWriterTSNat
32−#if MIN_VERSION_mtl(2,2,1)
33− , fromExceptT
34−#endif
35 -- ** Functions based on <https://hackage.haskell.org/package/mmorph mmorph>
31 -- ** Functions based on <https://hackage.haskell.org/package/mmorph mmorph>
36 , hoistNat
32 , hoistNat
37 , embedNat
33 , embedNat
@@ -113,7 +109,7 @@ serve p server = toApplication (runRouter (route p (return (RR (Right server))))
113-- Documentation
109-- Documentation
114
110
115-- $enterDoc
111-- $enterDoc
116−-- Sometimes our cherished `EitherT` monad isn't quite the type you'd like for
112+-- Sometimes our cherished `ExceptT` monad isn't quite the type you'd like for
117-- your handlers. Maybe you want to thread some configuration in a @Reader@
113-- your handlers. Maybe you want to thread some configuration in a @Reader@
118-- monad. Or have your types ensure that your handlers don't do any IO. Enter
114-- monad. Or have your types ensure that your handlers don't do any IO. Enter
119-- `enter`.
115-- `enter`.
servant-server/src/Servant/Server/Internal.hs+24−24
@@ -23,7 +23,7 @@ module Servant.Server.Internal
23#if !MIN_VERSION_base(4,8,0)
23#if !MIN_VERSION_base(4,8,0)
24import Control.Applicative ((<$>))
24import Control.Applicative ((<$>))
25#endif
25#endif
26−import Control.Monad.Trans.Either (EitherT)
26+import Control.Monad.Trans.Except (ExceptT)
27import qualified Data.ByteString as B
27import qualified Data.ByteString as B
28import qualified Data.ByteString.Lazy as BL
28import qualified Data.ByteString.Lazy as BL
29import qualified Data.Map as M
29import qualified Data.Map as M
@@ -65,7 +65,7 @@ class HasServer layout where
65
65
66 route :: Proxy layout -> IO (RouteResult (Server layout)) -> Router
66 route :: Proxy layout -> IO (RouteResult (Server layout)) -> Router
67
67
68−type Server layout = ServerT layout (EitherT ServantErr IO)
68+type Server layout = ServerT layout (ExceptT ServantErr IO)
69
69
70-- * Instances
70-- * Instances
71
71
@@ -107,7 +107,7 @@ captured _ = fromText
107-- >
107-- >
108-- > server :: Server MyApi
108-- > server :: Server MyApi
109-- > server = getBook
109-- > server = getBook
110−-- > where getBook :: Text -> EitherT ServantErr IO Book
110+-- > where getBook :: Text -> ExceptT ServantErr IO Book
111-- > getBook isbn = ...
111-- > getBook isbn = ...
112instance (KnownSymbol capture, FromText a, HasServer sublayout)
112instance (KnownSymbol capture, FromText a, HasServer sublayout)
113 => HasServer (Capture capture a :> sublayout) where
113 => HasServer (Capture capture a :> sublayout) where
@@ -142,7 +142,7 @@ processMethodRouter handleA status method headers request = case handleA of
142
142
143methodRouter :: (AllCTRender ctypes a)
143methodRouter :: (AllCTRender ctypes a)
144 => Method -> Proxy ctypes -> Status
144 => Method -> Proxy ctypes -> Status
145− -> IO (RouteResult (EitherT ServantErr IO a))
145+ -> IO (RouteResult (ExceptT ServantErr IO a))
146 -> Router
146 -> Router
147methodRouter method proxy status action = LeafRouter route'
147methodRouter method proxy status action = LeafRouter route'
148 where
148 where
@@ -158,7 +158,7 @@ methodRouter method proxy status action = LeafRouter route'
158
158
159methodRouterHeaders :: (GetHeaders (Headers h v), AllCTRender ctypes v)
159methodRouterHeaders :: (GetHeaders (Headers h v), AllCTRender ctypes v)
160 => Method -> Proxy ctypes -> Status
160 => Method -> Proxy ctypes -> Status
161− -> IO (RouteResult (EitherT ServantErr IO (Headers h v)))
161+ -> IO (RouteResult (ExceptT ServantErr IO (Headers h v)))
162 -> Router
162 -> Router
163methodRouterHeaders method proxy status action = LeafRouter route'
163methodRouterHeaders method proxy status action = LeafRouter route'
164 where
164 where
@@ -174,7 +174,7 @@ methodRouterHeaders method proxy status action = LeafRouter route'
174 | otherwise = respond $ failWith NotFound
174 | otherwise = respond $ failWith NotFound
175
175
176methodRouterEmpty :: Method
176methodRouterEmpty :: Method
177− -> IO (RouteResult (EitherT ServantErr IO ()))
177+ -> IO (RouteResult (ExceptT ServantErr IO ()))
178 -> Router
178 -> Router
179methodRouterEmpty method action = LeafRouter route'
179methodRouterEmpty method action = LeafRouter route'
180 where
180 where
@@ -192,9 +192,9 @@ methodRouterEmpty method action = LeafRouter route'
192--
192--
193-- The code of the handler will, just like
193-- The code of the handler will, just like
194-- for 'Servant.API.Get.Get', 'Servant.API.Post.Post' and
194-- for 'Servant.API.Get.Get', 'Servant.API.Post.Post' and
195−-- 'Servant.API.Put.Put', run in @EitherT ServantErr IO ()@.
195+-- 'Servant.API.Put.Put', run in @ExceptT ServantErr IO ()@.
196-- The 'Int' represents the status code and the 'String' a message
196-- The 'Int' represents the status code and the 'String' a message
197−-- to be returned. You can use 'Control.Monad.Trans.Either.left' to
197+-- to be returned. You can use 'Control.Monad.Trans.Except.throwE' to
198-- painlessly error out if the conditions for a successful deletion
198-- painlessly error out if the conditions for a successful deletion
199-- are not met.
199-- are not met.
200instance
200instance
@@ -233,9 +233,9 @@ instance
233-- | When implementing the handler for a 'Get' endpoint,
233-- | When implementing the handler for a 'Get' endpoint,
234-- just like for 'Servant.API.Delete.Delete', 'Servant.API.Post.Post'
234-- just like for 'Servant.API.Delete.Delete', 'Servant.API.Post.Post'
235-- and 'Servant.API.Put.Put', the handler code runs in the
235-- and 'Servant.API.Put.Put', the handler code runs in the
236−-- @EitherT ServantErr IO@ monad, where the 'Int' represents
236+-- @ExceptT ServantErr IO@ monad, where the 'Int' represents
237-- the status code and the 'String' a message, returned in case of
237-- the status code and the 'String' a message, returned in case of
238−-- failure. You can quite handily use 'Control.Monad.Trans.EitherT.left'
238+-- failure. You can quite handily use 'Control.Monad.Trans.Except.throwE'
239-- to quickly fail if some conditions are not met.
239-- to quickly fail if some conditions are not met.
240--
240--
241-- If successfully returning a value, we use the type-level list, combined
241-- If successfully returning a value, we use the type-level list, combined
@@ -294,7 +294,7 @@ instance
294-- >
294-- >
295-- > server :: Server MyApi
295-- > server :: Server MyApi
296-- > server = viewReferer
296-- > server = viewReferer
297−-- > where viewReferer :: Referer -> EitherT ServantErr IO referer
297+-- > where viewReferer :: Referer -> ExceptT ServantErr IO referer
298-- > viewReferer referer = return referer
298-- > viewReferer referer = return referer
299instance (KnownSymbol sym, FromText a, HasServer sublayout)
299instance (KnownSymbol sym, FromText a, HasServer sublayout)
300 => HasServer (Header sym a :> sublayout) where
300 => HasServer (Header sym a :> sublayout) where
@@ -310,9 +310,9 @@ instance (KnownSymbol sym, FromText a, HasServer sublayout)
310-- | When implementing the handler for a 'Post' endpoint,
310-- | When implementing the handler for a 'Post' endpoint,
311-- just like for 'Servant.API.Delete.Delete', 'Servant.API.Get.Get'
311-- just like for 'Servant.API.Delete.Delete', 'Servant.API.Get.Get'
312-- and 'Servant.API.Put.Put', the handler code runs in the
312-- and 'Servant.API.Put.Put', the handler code runs in the
313−-- @EitherT ServantErr IO@ monad, where the 'Int' represents
313+-- @ExceptT ServantErr IO@ monad, where the 'Int' represents
314-- the status code and the 'String' a message, returned in case of
314-- the status code and the 'String' a message, returned in case of
315−-- failure. You can quite handily use 'Control.Monad.Trans.EitherT.left'
315+-- failure. You can quite handily use 'Control.Monad.Trans.Except.throwE'
316-- to quickly fail if some conditions are not met.
316-- to quickly fail if some conditions are not met.
317--
317--
318-- If successfully returning a value, we use the type-level list, combined
318-- If successfully returning a value, we use the type-level list, combined
@@ -356,9 +356,9 @@ instance
356-- | When implementing the handler for a 'Put' endpoint,
356-- | When implementing the handler for a 'Put' endpoint,
357-- just like for 'Servant.API.Delete.Delete', 'Servant.API.Get.Get'
357-- just like for 'Servant.API.Delete.Delete', 'Servant.API.Get.Get'
358-- and 'Servant.API.Post.Post', the handler code runs in the
358-- and 'Servant.API.Post.Post', the handler code runs in the
359−-- @EitherT ServantErr IO@ monad, where the 'Int' represents
359+-- @ExceptT ServantErr IO@ monad, where the 'Int' represents
360-- the status code and the 'String' a message, returned in case of
360-- the status code and the 'String' a message, returned in case of
361−-- failure. You can quite handily use 'Control.Monad.Trans.EitherT.left'
361+-- failure. You can quite handily use 'Control.Monad.Trans.Except.throwE'
362-- to quickly fail if some conditions are not met.
362-- to quickly fail if some conditions are not met.
363--
363--
364-- If successfully returning a value, we use the type-level list, combined
364-- If successfully returning a value, we use the type-level list, combined
@@ -401,9 +401,9 @@ instance
401-- | When implementing the handler for a 'Patch' endpoint,
401-- | When implementing the handler for a 'Patch' endpoint,
402-- just like for 'Servant.API.Delete.Delete', 'Servant.API.Get.Get'
402-- just like for 'Servant.API.Delete.Delete', 'Servant.API.Get.Get'
403-- and 'Servant.API.Put.Put', the handler code runs in the
403-- and 'Servant.API.Put.Put', the handler code runs in the
404−-- @EitherT ServantErr IO@ monad, where the 'Int' represents
404+-- @ExceptT ServantErr IO@ monad, where the 'Int' represents
405-- the status code and the 'String' a message, returned in case of
405-- the status code and the 'String' a message, returned in case of
406−-- failure. You can quite handily use 'Control.Monad.Trans.EitherT.left'
406+-- failure. You can quite handily use 'Control.Monad.Trans.Except.throwE'
407-- to quickly fail if some conditions are not met.
407-- to quickly fail if some conditions are not met.
408--
408--
409-- If successfully returning a value, we just require that its type has
409-- If successfully returning a value, we just require that its type has
@@ -459,7 +459,7 @@ instance
459-- >
459-- >
460-- > server :: Server MyApi
460-- > server :: Server MyApi
461-- > server = getBooksBy
461-- > server = getBooksBy
462−-- > where getBooksBy :: Maybe Text -> EitherT ServantErr IO [Book]
462+-- > where getBooksBy :: Maybe Text -> ExceptT ServantErr IO [Book]
463-- > getBooksBy Nothing = ...return all books...
463-- > getBooksBy Nothing = ...return all books...
464-- > getBooksBy (Just author) = ...return books by the given author...
464-- > getBooksBy (Just author) = ...return books by the given author...
465instance (KnownSymbol sym, FromText a, HasServer sublayout)
465instance (KnownSymbol sym, FromText a, HasServer sublayout)
@@ -496,7 +496,7 @@ instance (KnownSymbol sym, FromText a, HasServer sublayout)
496-- >
496-- >
497-- > server :: Server MyApi
497-- > server :: Server MyApi
498-- > server = getBooksBy
498-- > server = getBooksBy
499−-- > where getBooksBy :: [Text] -> EitherT ServantErr IO [Book]
499+-- > where getBooksBy :: [Text] -> ExceptT ServantErr IO [Book]
500-- > getBooksBy authors = ...return all books by these authors...
500-- > getBooksBy authors = ...return all books by these authors...
501instance (KnownSymbol sym, FromText a, HasServer sublayout)
501instance (KnownSymbol sym, FromText a, HasServer sublayout)
502 => HasServer (QueryParams sym a :> sublayout) where
502 => HasServer (QueryParams sym a :> sublayout) where
@@ -527,7 +527,7 @@ instance (KnownSymbol sym, FromText a, HasServer sublayout)
527-- >
527-- >
528-- > server :: Server MyApi
528-- > server :: Server MyApi
529-- > server = getBooks
529-- > server = getBooks
530−-- > where getBooks :: Bool -> EitherT ServantErr IO [Book]
530+-- > where getBooks :: Bool -> ExceptT ServantErr IO [Book]
531-- > getBooks onlyPublished = ...return all books, or only the ones that are already published, depending on the argument...
531-- > getBooks onlyPublished = ...return all books, or only the ones that are already published, depending on the argument...
532instance (KnownSymbol sym, HasServer sublayout)
532instance (KnownSymbol sym, HasServer sublayout)
533 => HasServer (QueryFlag sym :> sublayout) where
533 => HasServer (QueryFlag sym :> sublayout) where
@@ -567,7 +567,7 @@ parseMatrixText = parseQueryText
567-- >
567-- >
568-- > server :: Server MyApi
568-- > server :: Server MyApi
569-- > server = getBooksBy
569-- > server = getBooksBy
570−-- > where getBooksBy :: Maybe Text -> EitherT ServantErr IO [Book]
570+-- > where getBooksBy :: Maybe Text -> ExceptT ServantErr IO [Book]
571-- > getBooksBy Nothing = ...return all books...
571-- > getBooksBy Nothing = ...return all books...
572-- > getBooksBy (Just author) = ...return books by the given author...
572-- > getBooksBy (Just author) = ...return books by the given author...
573instance (KnownSymbol sym, FromText a, HasServer sublayout)
573instance (KnownSymbol sym, FromText a, HasServer sublayout)
@@ -607,7 +607,7 @@ instance (KnownSymbol sym, FromText a, HasServer sublayout)
607-- >
607-- >
608-- > server :: Server MyApi
608-- > server :: Server MyApi
609-- > server = getBooksBy
609-- > server = getBooksBy
610−-- > where getBooksBy :: [Text] -> EitherT ServantErr IO [Book]
610+-- > where getBooksBy :: [Text] -> ExceptT ServantErr IO [Book]
611-- > getBooksBy authors = ...return all books by these authors...
611-- > getBooksBy authors = ...return all books by these authors...
612instance (KnownSymbol sym, FromText a, HasServer sublayout)
612instance (KnownSymbol sym, FromText a, HasServer sublayout)
613 => HasServer (MatrixParams sym a :> sublayout) where
613 => HasServer (MatrixParams sym a :> sublayout) where
@@ -641,7 +641,7 @@ instance (KnownSymbol sym, FromText a, HasServer sublayout)
641-- >
641-- >
642-- > server :: Server MyApi
642-- > server :: Server MyApi
643-- > server = getBooks
643-- > server = getBooks
644−-- > where getBooks :: Bool -> EitherT ServantErr IO [Book]
644+-- > where getBooks :: Bool -> ExceptT ServantErr IO [Book]
645-- > getBooks onlyPublished = ...return all books, or only the ones that are already published, depending on the argument...
645-- > getBooks onlyPublished = ...return all books, or only the ones that are already published, depending on the argument...
646instance (KnownSymbol sym, HasServer sublayout)
646instance (KnownSymbol sym, HasServer sublayout)
647 => HasServer (MatrixFlag sym :> sublayout) where
647 => HasServer (MatrixFlag sym :> sublayout) where
@@ -699,7 +699,7 @@ instance HasServer Raw where
699-- >
699-- >
700-- > server :: Server MyApi
700-- > server :: Server MyApi
701-- > server = postBook
701-- > server = postBook
702−-- > where postBook :: Book -> EitherT ServantErr IO Book
702+-- > where postBook :: Book -> ExceptT ServantErr IO Book
703-- > postBook book = ...insert into your db...
703-- > postBook book = ...insert into your db...
704instance ( AllCTUnrender list a, HasServer sublayout
704instance ( AllCTUnrender list a, HasServer sublayout
705 ) => HasServer (ReqBody list a :> sublayout) where
705 ) => HasServer (ReqBody list a :> sublayout) where
servant-server/src/Servant/Server/Internal/Enter.hs−8
@@ -22,9 +22,6 @@ import Control.Monad.Morph
22import Control.Monad.Reader
22import Control.Monad.Reader
23import qualified Control.Monad.State.Lazy as LState
23import qualified Control.Monad.State.Lazy as LState
24import qualified Control.Monad.State.Strict as SState
24import qualified Control.Monad.State.Strict as SState
25−#if MIN_VERSION_mtl(2,2,1)
26−import Control.Monad.Trans.Either
27−#endif
28import qualified Control.Monad.Writer.Lazy as LWriter
25import qualified Control.Monad.Writer.Lazy as LWriter
29import qualified Control.Monad.Writer.Strict as SWriter
26import qualified Control.Monad.Writer.Strict as SWriter
30import Data.Typeable
27import Data.Typeable
@@ -83,11 +80,6 @@ logWriterTLNat logger = Nat $ \x -> do
83 liftIO $ logger w
80 liftIO $ logger w
84 return a
81 return a
85
82
86−#if MIN_VERSION_mtl(2,2,1)
87−fromExceptT :: ExceptT e m :~> EitherT e m
88−fromExceptT = Nat $ \x -> EitherT $ runExceptT x
89−#endif
90−
91-- | Like @mmorph@'s `hoist`.
83-- | Like @mmorph@'s `hoist`.
92hoistNat :: (MFunctor t, Monad m) => (m :~> n) -> (t m :~> t n)
84hoistNat :: (MFunctor t, Monad m) => (m :~> n) -> (t m :~> t n)
93hoistNat (Nat n) = Nat $ hoist n
85hoistNat (Nat n) = Nat $ hoist n
servant-server/src/Servant/Server/Internal/RoutingApplication.hs+3−3
@@ -8,7 +8,7 @@ module Servant.Server.Internal.RoutingApplication where
8import Control.Applicative (Applicative, (<$>))
8import Control.Applicative (Applicative, (<$>))
9import Data.Monoid (Monoid, mappend, mempty)
9import Data.Monoid (Monoid, mappend, mempty)
10#endif
10#endif
11−import Control.Monad.Trans.Either (EitherT, runEitherT)
11+import Control.Monad.Trans.Except (ExceptT, runExceptT)
12import qualified Data.ByteString as B
12import qualified Data.ByteString as B
13import qualified Data.ByteString.Lazy as BL
13import qualified Data.ByteString.Lazy as BL
14import Data.IORef (newIORef, readIORef,
14import Data.IORef (newIORef, readIORef,
@@ -107,7 +107,7 @@ toApplication ra request respond = do
107 routingRespond (Right response) =
107 routingRespond (Right response) =
108 respond response
108 respond response
109
109
110−runAction :: IO (RouteResult (EitherT ServantErr IO a))
110+runAction :: IO (RouteResult (ExceptT ServantErr IO a))
111 -> (RouteResult Response -> IO r)
111 -> (RouteResult Response -> IO r)
112 -> (a -> RouteResult Response)
112 -> (a -> RouteResult Response)
113 -> IO r
113 -> IO r
@@ -116,7 +116,7 @@ runAction action respond k = do
116 go r
116 go r
117 where
117 where
118 go (RR (Right a)) = do
118 go (RR (Right a)) = do
119− e <- runEitherT a
119+ e <- runExceptT a
120 respond $ case e of
120 respond $ case e of
121 Right x -> k x
121 Right x -> k x
122 Left err -> succeedWith $ responseServantErr err
122 Left err -> succeedWith $ responseServantErr err
servant-server/test/Servant/Server/Internal/EnterSpec.hs+2−2
@@ -5,7 +5,7 @@ module Servant.Server.Internal.EnterSpec where
5
5
6import qualified Control.Category as C
6import qualified Control.Category as C
7import Control.Monad.Reader
7import Control.Monad.Reader
8−import Control.Monad.Trans.Either
8+import Control.Monad.Trans.Except
9import Data.Proxy
9import Data.Proxy
10import Servant.API
10import Servant.API
11import Servant.Server
11import Servant.Server
@@ -34,7 +34,7 @@ combinedAPI = Proxy
34readerServer' :: ServerT ReaderAPI (Reader String)
34readerServer' :: ServerT ReaderAPI (Reader String)
35readerServer' = return 1797 :<|> ask
35readerServer' = return 1797 :<|> ask
36
36
37−fReader :: Reader String :~> EitherT ServantErr IO
37+fReader :: Reader String :~> ExceptT ServantErr IO
38fReader = generalizeNat C.. (runReaderTNat "hi")
38fReader = generalizeNat C.. (runReaderTNat "hi")
39
39
40readerServer :: Server ReaderAPI
40readerServer :: Server ReaderAPI
servant-server/test/Servant/ServerSpec.hs+5−5
@@ -10,7 +10,7 @@ module Servant.ServerSpec where
10
10
11
11
12import Control.Monad (forM_, when)
12import Control.Monad (forM_, when)
13−import Control.Monad.Trans.Either (EitherT, left)
13+import Control.Monad.Trans.Except (ExceptT, throwE)
14import Data.Aeson (FromJSON, ToJSON, decode', encode)
14import Data.Aeson (FromJSON, ToJSON, decode', encode)
15import Data.ByteString.Conversion ()
15import Data.ByteString.Conversion ()
16import Data.Char (toUpper)
16import Data.Char (toUpper)
@@ -99,11 +99,11 @@ spec = do
99type CaptureApi = Capture "legs" Integer :> Get '[JSON] Animal
99type CaptureApi = Capture "legs" Integer :> Get '[JSON] Animal
100captureApi :: Proxy CaptureApi
100captureApi :: Proxy CaptureApi
101captureApi = Proxy
101captureApi = Proxy
102−captureServer :: Integer -> EitherT ServantErr IO Animal
102+captureServer :: Integer -> ExceptT ServantErr IO Animal
103captureServer legs = case legs of
103captureServer legs = case legs of
104 4 -> return jerry
104 4 -> return jerry
105 2 -> return tweety
105 2 -> return tweety
106− _ -> left err404
106+ _ -> throwE err404
107
107
108captureSpec :: Spec
108captureSpec :: Spec
109captureSpec = do
109captureSpec = do
@@ -481,11 +481,11 @@ headerApi = Proxy
481headerSpec :: Spec
481headerSpec :: Spec
482headerSpec = describe "Servant.API.Header" $ do
482headerSpec = describe "Servant.API.Header" $ do
483
483
484− let expectsInt :: Maybe Int -> EitherT ServantErr IO ()
484+ let expectsInt :: Maybe Int -> ExceptT ServantErr IO ()
485 expectsInt (Just x) = when (x /= 5) $ error "Expected 5"
485 expectsInt (Just x) = when (x /= 5) $ error "Expected 5"
486 expectsInt Nothing = error "Expected an int"
486 expectsInt Nothing = error "Expected an int"
487
487
488− let expectsString :: Maybe String -> EitherT ServantErr IO ()
488+ let expectsString :: Maybe String -> ExceptT ServantErr IO ()
489 expectsString (Just x) = when (x /= "more from you") $ error "Expected more from you"
489 expectsString (Just x) = when (x /= "more from you") $ error "Expected more from you"
490 expectsString Nothing = error "Expected a string"
490 expectsString Nothing = error "Expected a string"
491
491
stack.yaml+1−1
@@ -14,4 +14,4 @@ packages:
14- servant-server/
14- servant-server/
15extra-deps:
15extra-deps:
16- engine-io-wai-1.0.2
16- engine-io-wai-1.0.2
17−resolver: nightly-2015-09-05
17+resolver: nightly-2015-09-10