@@ -25,7 +25,7 @@ module Servant.Client
25import Control.Applicative ((<$>))
25import Control.Applicative ((<$>))
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
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
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
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
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
@@ -140,7 +140,7 @@ instance
140 {-# OVERLAPPING #-}
140 {-# OVERLAPPING #-}
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
@@ -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 #-}
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
@@ -180,7 +180,7 @@ instance
180 {-# OVERLAPPING #-}
180 {-# OVERLAPPING #-}
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
@@ -192,7 +192,7 @@ instance
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
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 #-}
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
@@ -261,7 +261,7 @@ instance
261 {-# OVERLAPPING #-}
261 {-# OVERLAPPING #-}
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
@@ -273,7 +273,7 @@ instance
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 #-}
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
@@ -300,7 +300,7 @@ instance
300 {-# OVERLAPPING #-}
300 {-# OVERLAPPING #-}
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
@@ -312,7 +312,7 @@ instance
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 #-}
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
@@ -339,7 +339,7 @@ instance
339 {-# OVERLAPPING #-}
339 {-# OVERLAPPING #-}
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
@@ -351,7 +351,7 @@ instance
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
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
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
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
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
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
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)
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
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