on master help sign in
remove unsed type and clean up
7c24c2aBrandon Martin
servant-client/src/Servant/Client.hs+20−22
@@ -36,8 +36,6 @@ import Network.HTTP.Media
36import qualified Network.HTTP.Types as H
36import qualified Network.HTTP.Types as H
37import qualified Network.HTTP.Types.Header as HTTP
37import qualified Network.HTTP.Types.Header as HTTP
38import Servant.API
38import Servant.API
39−import Servant.API.ResponseHeaders
40−import Servant.API.ContentTypes
41import Servant.Common.BaseUrl
39import Servant.Common.BaseUrl
42import Servant.Common.Req
40import Servant.Common.Req
43
41
@@ -54,15 +52,15 @@ import Servant.Common.Req
54-- > getAllBooks :: BaseUrl -> EitherT String IO [Book]
52-- > getAllBooks :: BaseUrl -> EitherT String IO [Book]
55-- > postNewBook :: Book -> BaseUrl -> EitherT String IO Book
53-- > postNewBook :: Book -> BaseUrl -> EitherT String IO Book
56-- > (getAllBooks :<|> postNewBook) = client myApi
54-- > (getAllBooks :<|> postNewBook) = client myApi
57−client :: HasClient layout => Proxy layout -> Client layout
55+client :: HasClient layout => Proxy layout -> BaseUrl -> Client layout
58−client p = clientWithRoute p defReq
56+client p baseurl = clientWithRoute p defReq baseurl
59
57
60-- | This class lets us define how each API combinator
58-- | This class lets us define how each API combinator
61-- influences the creation of an HTTP request. It's mostly
59-- influences the creation of an HTTP request. It's mostly
62-- an internal class, you can just use 'client'.
60-- an internal class, you can just use 'client'.
63class HasClient layout where
61class HasClient layout where
64 type Client' layout :: *
62 type Client' layout :: *
65− clientWithRoute :: Proxy layout -> Req -> Client layout
63+ clientWithRoute :: Proxy layout -> Req -> BaseUrl -> Client' layout
66
64
67type Client layout = Client' layout
65type Client layout = Client' layout
68
66
@@ -80,10 +78,10 @@ type Client layout = Client' layout
80-- > postNewBook :: Book -> BaseUrl -> EitherT String IO Book
78-- > postNewBook :: Book -> BaseUrl -> EitherT String IO Book
81-- > (getAllBooks :<|> postNewBook) = client myApi
79-- > (getAllBooks :<|> postNewBook) = client myApi
82instance (HasClient a, HasClient b) => HasClient (a :<|> b) where
80instance (HasClient a, HasClient b) => HasClient (a :<|> b) where
83− type Client (a :<|> b) = Client a :<|> Client b
81+ type Client' (a :<|> b) = Client' a :<|> Client' b
84− clientWithRoute Proxy req =
82+ clientWithRoute Proxy req baseurl =
85− clientWithRoute (Proxy :: Proxy a) req :<|>
83+ clientWithRoute (Proxy :: Proxy a) req baseurl :<|>
86− clientWithRoute (Proxy :: Proxy b) req
84+ clientWithRoute (Proxy :: Proxy b) req baseurl
87
85
88-- | If you use a 'Capture' in one of your endpoints in your API,
86-- | If you use a 'Capture' in one of your endpoints in your API,
89-- the corresponding querying function will automatically take
87-- the corresponding querying function will automatically take
@@ -126,7 +124,7 @@ instance
126 {-# OVERLAPPABLE #-}
124 {-# OVERLAPPABLE #-}
127#endif
125#endif
128 (MimeUnrender ct a) => HasClient (Delete (ct ': cts) a) where
126 (MimeUnrender ct a) => HasClient (Delete (ct ': cts) a) where
129− type Client (Delete (ct ': cts) a) = EitherT ServantError IO a
127+ type Client' (Delete (ct ': cts) a) = EitherT ServantError IO a
130 clientWithRoute Proxy req baseurl =
128 clientWithRoute Proxy req baseurl =
131 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodDelete req [200, 202] baseurl
129 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodDelete req [200, 202] baseurl
132
130
@@ -137,7 +135,7 @@ instance
137 {-# OVERLAPPING #-}
135 {-# OVERLAPPING #-}
138#endif
136#endif
139 HasClient (Delete (ct ': cts) ()) where
137 HasClient (Delete (ct ': cts) ()) where
140− type Client (Delete (ct ': cts) ()) = EitherT ServantError IO ()
138+ type Client' (Delete (ct ': cts) ()) = EitherT ServantError IO ()
141 clientWithRoute Proxy req baseurl =
139 clientWithRoute Proxy req baseurl =
142 void $ performRequestNoBody H.methodDelete req [204] baseurl
140 void $ performRequestNoBody H.methodDelete req [204] baseurl
143
141
@@ -149,7 +147,7 @@ instance
149#endif
147#endif
150 ( MimeUnrender ct a, BuildHeadersTo ls
148 ( MimeUnrender ct a, BuildHeadersTo ls
151 ) => HasClient (Delete (ct ': cts) (Headers ls a)) where
149 ) => HasClient (Delete (ct ': cts) (Headers ls a)) where
152− type Client (Delete (ct ': cts) (Headers ls a)) = EitherT ServantError IO (Headers ls a)
150+ type Client' (Delete (ct ': cts) (Headers ls a)) = EitherT ServantError IO (Headers ls a)
153 clientWithRoute Proxy req baseurl = do
151 clientWithRoute Proxy req baseurl = do
154 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodDelete req [200, 202] baseurl
152 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodDelete req [200, 202] baseurl
155 return $ Headers { getResponse = resp
153 return $ Headers { getResponse = resp
@@ -165,7 +163,7 @@ instance
165 {-# OVERLAPPABLE #-}
163 {-# OVERLAPPABLE #-}
166#endif
164#endif
167 (MimeUnrender ct result) => HasClient (Get (ct ': cts) result) where
165 (MimeUnrender ct result) => HasClient (Get (ct ': cts) result) where
168− type Client (Get (ct ': cts) result) = EitherT ServantError IO result
166+ type Client' (Get (ct ': cts) result) = EitherT ServantError IO result
169 clientWithRoute Proxy req baseurl =
167 clientWithRoute Proxy req baseurl =
170 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodGet req [200, 203] baseurl
168 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodGet req [200, 203] baseurl
171
169
@@ -176,7 +174,7 @@ instance
176 {-# OVERLAPPING #-}
174 {-# OVERLAPPING #-}
177#endif
175#endif
178 HasClient (Get (ct ': cts) ()) where
176 HasClient (Get (ct ': cts) ()) where
179− type Client (Get (ct ': cts) ()) = EitherT ServantError IO ()
177+ type Client' (Get (ct ': cts) ()) = EitherT ServantError IO ()
180 clientWithRoute Proxy req baseurl =
178 clientWithRoute Proxy req baseurl =
181 performRequestNoBody H.methodGet req [204] baseurl
179 performRequestNoBody H.methodGet req [204] baseurl
182
180
@@ -245,7 +243,7 @@ instance
245 {-# OVERLAPPABLE #-}
243 {-# OVERLAPPABLE #-}
246#endif
244#endif
247 (MimeUnrender ct a) => HasClient (Post (ct ': cts) a) where
245 (MimeUnrender ct a) => HasClient (Post (ct ': cts) a) where
248− type Client (Post (ct ': cts) a) = EitherT ServantError IO a
246+ type Client' (Post (ct ': cts) a) = EitherT ServantError IO a
249 clientWithRoute Proxy req baseurl =
247 clientWithRoute Proxy req baseurl =
250 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPost req [200,201] baseurl
248 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPost req [200,201] baseurl
251
249
@@ -256,7 +254,7 @@ instance
256 {-# OVERLAPPING #-}
254 {-# OVERLAPPING #-}
257#endif
255#endif
258 HasClient (Post (ct ': cts) ()) where
256 HasClient (Post (ct ': cts) ()) where
259− type Client (Post (ct ': cts) ()) = EitherT ServantError IO ()
257+ type Client' (Post (ct ': cts) ()) = EitherT ServantError IO ()
260 clientWithRoute Proxy req baseurl =
258 clientWithRoute Proxy req baseurl =
261 void $ performRequestNoBody H.methodPost req [204] baseurl
259 void $ performRequestNoBody H.methodPost req [204] baseurl
262
260
@@ -284,7 +282,7 @@ instance
284 {-# OVERLAPPABLE #-}
282 {-# OVERLAPPABLE #-}
285#endif
283#endif
286 (MimeUnrender ct a) => HasClient (Put (ct ': cts) a) where
284 (MimeUnrender ct a) => HasClient (Put (ct ': cts) a) where
287− type Client (Put (ct ': cts) a) = EitherT ServantError IO a
285+ type Client' (Put (ct ': cts) a) = EitherT ServantError IO a
288 clientWithRoute Proxy req baseurl =
286 clientWithRoute Proxy req baseurl =
289 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPut req [200,201] baseurl
287 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPut req [200,201] baseurl
290
288
@@ -295,7 +293,7 @@ instance
295 {-# OVERLAPPING #-}
293 {-# OVERLAPPING #-}
296#endif
294#endif
297 HasClient (Put (ct ': cts) ()) where
295 HasClient (Put (ct ': cts) ()) where
298− type Client (Put (ct ': cts) ()) = EitherT ServantError IO ()
296+ type Client' (Put (ct ': cts) ()) = EitherT ServantError IO ()
299 clientWithRoute Proxy req baseurl =
297 clientWithRoute Proxy req baseurl =
300 void $ performRequestNoBody H.methodPut req [204] baseurl
298 void $ performRequestNoBody H.methodPut req [204] baseurl
301
299
@@ -323,7 +321,7 @@ instance
323 {-# OVERLAPPABLE #-}
321 {-# OVERLAPPABLE #-}
324#endif
322#endif
325 (MimeUnrender ct a) => HasClient (Patch (ct ': cts) a) where
323 (MimeUnrender ct a) => HasClient (Patch (ct ': cts) a) where
326− type Client (Patch (ct ': cts) a) = EitherT ServantError IO a
324+ type Client' (Patch (ct ': cts) a) = EitherT ServantError IO a
327 clientWithRoute Proxy req baseurl =
325 clientWithRoute Proxy req baseurl =
328 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPatch req [200,201] baseurl
326 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPatch req [200,201] baseurl
329
327
@@ -334,7 +332,7 @@ instance
334 {-# OVERLAPPING #-}
332 {-# OVERLAPPING #-}
335#endif
333#endif
336 HasClient (Patch (ct ': cts) ()) where
334 HasClient (Patch (ct ': cts) ()) where
337− type Client (Patch (ct ': cts) ()) = EitherT ServantError IO ()
335+ type Client' (Patch (ct ': cts) ()) = EitherT ServantError IO ()
338 clientWithRoute Proxy req baseurl =
336 clientWithRoute Proxy req baseurl =
339 void $ performRequestNoBody H.methodPatch req [204] baseurl
337 void $ performRequestNoBody H.methodPatch req [204] baseurl
340
338
@@ -609,8 +607,8 @@ instance (KnownSymbol sym, HasClient sublayout)
609instance HasClient Raw where
607instance HasClient Raw where
610 type Client' Raw = H.Method -> EitherT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], Response ByteString)
608 type Client' Raw = H.Method -> EitherT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], Response ByteString)
611
609
612− clientWithRoute :: Proxy Raw -> Req -> Client Raw
610+ clientWithRoute :: Proxy Raw -> Req -> BaseUrl -> Client' Raw
613− clientWithRoute Proxy req httpMethod baseurl = do
611+ clientWithRoute Proxy req baseurl httpMethod = do
614 performRequest httpMethod req (const True) baseurl
612 performRequest httpMethod req (const True) baseurl
615
613
616-- | If you use a 'ReqBody' in one of your endpoints in your API,
614-- | If you use a 'ReqBody' in one of your endpoints in your API,
servant-client/test/Servant/ClientSpec.hs+1−5
@@ -81,7 +81,6 @@ type TestHeaders = '[Header "X-Example1" Int, Header "X-Example2" String]
81type Api =
81type Api =
82 "get" :> Get '[JSON] Person
82 "get" :> Get '[JSON] Person
83 :<|> "delete" :> Delete '[JSON] ()
83 :<|> "delete" :> Delete '[JSON] ()
84− :<|> "deleteString" :> Delete '[JSON] String
85 :<|> "capture" :> Capture "name" String :> Get '[JSON,FormUrlEncoded] Person
84 :<|> "capture" :> Capture "name" String :> Get '[JSON,FormUrlEncoded] Person
86 :<|> "body" :> ReqBody '[FormUrlEncoded,JSON] Person :> Post '[JSON] Person
85 :<|> "body" :> ReqBody '[FormUrlEncoded,JSON] Person :> Post '[JSON] Person
87 :<|> "param" :> QueryParam "name" String :> Get '[FormUrlEncoded,JSON] Person
86 :<|> "param" :> QueryParam "name" String :> Get '[FormUrlEncoded,JSON] Person
@@ -106,7 +105,6 @@ server :: Application
106server = serve api (
105server = serve api (
107 return alice
106 return alice
108 :<|> return ()
107 :<|> return ()
109− :<|> return "ok"
110 :<|> (\ name -> return $ Person name 0)
108 :<|> (\ name -> return $ Person name 0)
111 :<|> return
109 :<|> return
112 :<|> (\ name -> case name of
110 :<|> (\ name -> case name of
@@ -267,14 +265,12 @@ spec = withServer $ \ baseUrl -> do
267 Left FailureResponse{..} <- runEitherT getResponse
265 Left FailureResponse{..} <- runEitherT getResponse
268 responseStatus `shouldBe` (Status 500 "error message")
266 responseStatus `shouldBe` (Status 500 "error message")
269 mapM_ test $
267 mapM_ test $
270− (WrappedApi (Proxy :: Proxy Delete), "Delete") :
268+ (WrappedApi (Proxy :: Proxy (Delete '[JSON] ())), "Delete") :
271 (WrappedApi (Proxy :: Proxy (Get '[JSON] ())), "Get") :
269 (WrappedApi (Proxy :: Proxy (Get '[JSON] ())), "Get") :
272 (WrappedApi (Proxy :: Proxy (Post '[JSON] ())), "Post") :
270 (WrappedApi (Proxy :: Proxy (Post '[JSON] ())), "Post") :
273 (WrappedApi (Proxy :: Proxy (Put '[JSON] ())), "Put") :
271 (WrappedApi (Proxy :: Proxy (Put '[JSON] ())), "Put") :
274 []
272 []
275
273
276−type RawRight = (Int, ByteString, MediaType, [HTTP.Header], C.Response ByteString)
277−
278failSpec :: IO ()
274failSpec :: IO ()
279failSpec = withFailServer $ \ baseUrl -> do
275failSpec = withFailServer $ \ baseUrl -> do
280 let getGet :: EitherT ServantError IO Person
276 let getGet :: EitherT ServantError IO Person
servant-docs/example/greet.hs−1
@@ -8,7 +8,6 @@
8import Control.Lens
8import Control.Lens
9import Data.Aeson
9import Data.Aeson
10import Data.Proxy
10import Data.Proxy
11−import Data.ByteString.Conversion
12import Data.String.Conversions
11import Data.String.Conversions
13import Data.Text (Text)
12import Data.Text (Text)
14import GHC.Generics
13import GHC.Generics
servant-docs/src/Servant/Docs/Internal.hs+1−25
@@ -40,7 +40,6 @@ import GHC.Generics
40import GHC.TypeLits
40import GHC.TypeLits
41import Servant.API
41import Servant.API
42import Servant.API.ContentTypes
42import Servant.API.ContentTypes
43−import Servant.API.ResponseHeaders
44import Servant.Utils.Links
43import Servant.Utils.Links
45
44
46import qualified Data.HashMap.Strict as HM
45import qualified Data.HashMap.Strict as HM
@@ -396,6 +395,7 @@ instance ToSample a b => ToSample (Headers ls a) b where
396 toSample _ = toSample (Proxy :: Proxy a)
395 toSample _ = toSample (Proxy :: Proxy a)
397 toSamples _ = toSamples (Proxy :: Proxy a)
396 toSamples _ = toSamples (Proxy :: Proxy a)
398
397
398+
399class AllHeaderSamples ls where
399class AllHeaderSamples ls where
400 allHeaderToSample :: Proxy ls -> [HTTP.Header]
400 allHeaderToSample :: Proxy ls -> [HTTP.Header]
401
401
@@ -684,15 +684,11 @@ instance
684 t = Proxy :: Proxy cts
684 t = Proxy :: Proxy cts
685 p = Proxy :: Proxy a
685 p = Proxy :: Proxy a
686
686
687−<<<<<<< HEAD
688instance
687instance
689#if MIN_VERSION_base(4,8,0)
688#if MIN_VERSION_base(4,8,0)
690 {-# OVERLAPPABLe #-}
689 {-# OVERLAPPABLe #-}
691#endif
690#endif
692 (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
691 (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
693−=======
694−instance (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
695−>>>>>>> Headers for all
696 => HasDocs (Get cts a) where
692 => HasDocs (Get cts a) where
697 docsFor Proxy (endpoint, action) =
693 docsFor Proxy (endpoint, action) =
698 single endpoint' action'
694 single endpoint' action'
@@ -703,15 +699,11 @@ instance (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
703 t = Proxy :: Proxy cts
699 t = Proxy :: Proxy cts
704 p = Proxy :: Proxy a
700 p = Proxy :: Proxy a
705
701
706−<<<<<<< HEAD
707instance
702instance
708#if MIN_VERSION_base(4,8,0)
703#if MIN_VERSION_base(4,8,0)
709 {-# OVERLAPPING #-}
704 {-# OVERLAPPING #-}
710#endif
705#endif
711 (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts
706 (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts
712−=======
713−instance (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts
714−>>>>>>> Headers for all
715 , AllHeaderSamples ls , GetHeaders (HList ls) )
707 , AllHeaderSamples ls , GetHeaders (HList ls) )
716 => HasDocs (Get cts (Headers ls a)) where
708 => HasDocs (Get cts (Headers ls a)) where
717 docsFor Proxy (endpoint, action) =
709 docsFor Proxy (endpoint, action) =
@@ -734,15 +726,11 @@ instance (KnownSymbol sym, HasDocs sublayout)
734 action' = over headers (|> headername) action
726 action' = over headers (|> headername) action
735 headername = pack $ symbolVal (Proxy :: Proxy sym)
727 headername = pack $ symbolVal (Proxy :: Proxy sym)
736
728
737−<<<<<<< HEAD
738instance
729instance
739#if MIN_VERSION_base(4,8,0)
730#if MIN_VERSION_base(4,8,0)
740 {-# OVERLAPPABLE #-}
731 {-# OVERLAPPABLE #-}
741#endif
732#endif
742 (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
733 (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
743−=======
744−instance (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
745−>>>>>>> Headers for all
746 => HasDocs (Post cts a) where
734 => HasDocs (Post cts a) where
747 docsFor Proxy (endpoint, action) =
735 docsFor Proxy (endpoint, action) =
748 single endpoint' action'
736 single endpoint' action'
@@ -754,15 +742,11 @@ instance (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
754 t = Proxy :: Proxy cts
742 t = Proxy :: Proxy cts
755 p = Proxy :: Proxy a
743 p = Proxy :: Proxy a
756
744
757−<<<<<<< HEAD
758instance
745instance
759#if MIN_VERSION_base(4,8,0)
746#if MIN_VERSION_base(4,8,0)
760 {-# OVERLAPPING #-}
747 {-# OVERLAPPING #-}
761#endif
748#endif
762 (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts
749 (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts
763−=======
764−instance (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts
765−>>>>>>> Headers for all
766 , AllHeaderSamples ls , GetHeaders (HList ls) )
750 , AllHeaderSamples ls , GetHeaders (HList ls) )
767 => HasDocs (Post cts (Headers ls a)) where
751 => HasDocs (Post cts (Headers ls a)) where
768 docsFor Proxy (endpoint, action) =
752 docsFor Proxy (endpoint, action) =
@@ -777,15 +761,11 @@ instance (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts
777 t = Proxy :: Proxy cts
761 t = Proxy :: Proxy cts
778 p = Proxy :: Proxy a
762 p = Proxy :: Proxy a
779
763
780−<<<<<<< HEAD
781instance
764instance
782#if MIN_VERSION_base(4,8,0)
765#if MIN_VERSION_base(4,8,0)
783 {-# OVERLAPPABLE #-}
766 {-# OVERLAPPABLE #-}
784#endif
767#endif
785 (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
768 (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
786−=======
787−instance (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
788−>>>>>>> Headers for all
789 => HasDocs (Put cts a) where
769 => HasDocs (Put cts a) where
790 docsFor Proxy (endpoint, action) =
770 docsFor Proxy (endpoint, action) =
791 single endpoint' action'
771 single endpoint' action'
@@ -797,15 +777,11 @@ instance (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
797 t = Proxy :: Proxy cts
777 t = Proxy :: Proxy cts
798 p = Proxy :: Proxy a
778 p = Proxy :: Proxy a
799
779
800−<<<<<<< HEAD
801instance
780instance
802#if MIN_VERSION_base(4,8,0)
781#if MIN_VERSION_base(4,8,0)
803 {-# OVERLAPPING #-}
782 {-# OVERLAPPING #-}
804#endif
783#endif
805 (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts
784 (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts
806−=======
807−instance (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts
808−>>>>>>> Headers for all
809 , AllHeaderSamples ls , GetHeaders (HList ls) )
785 , AllHeaderSamples ls , GetHeaders (HList ls) )
810 => HasDocs (Put cts (Headers ls a)) where
786 => HasDocs (Put cts (Headers ls a)) where
811 docsFor Proxy (endpoint, action) =
787 docsFor Proxy (endpoint, action) =
servant-examples/hackage/hackage.hs+8−11
@@ -54,29 +54,26 @@ instance FromJSON Package
54hackageAPI :: Proxy HackageAPI
54hackageAPI :: Proxy HackageAPI
55hackageAPI = Proxy
55hackageAPI = Proxy
56
56
57−getUsers :: BaseUrl -> EitherT ServantError IO [UserSummary]
57+getUsers :: EitherT ServantError IO [UserSummary]
58−getUser :: Username -> BaseUrl -> EitherT ServantError IO UserDetailed
58+getUser :: Username -> EitherT ServantError IO UserDetailed
59−getPackages :: BaseUrl -> EitherT ServantError IO [Package]
59+getPackages :: EitherT ServantError IO [Package]
60−getUsers :<|> getUser :<|> getPackages = client hackageAPI
60+getUsers :<|> getUser :<|> getPackages = client hackageAPI $ BaseUrl Http "hackage.haskell.org" 80
61−
62−run :: (BaseUrl -> r) -> r
63−run f = f (BaseUrl Http "hackage.haskell.org" 80)
64
61
65main :: IO ()
62main :: IO ()
66main = print =<< uselessNumbers
63main = print =<< uselessNumbers
67
64
68uselessNumbers :: IO (Either ServantError ())
65uselessNumbers :: IO (Either ServantError ())
69uselessNumbers = runEitherT $ do
66uselessNumbers = runEitherT $ do
70− users <- run getUsers
67+ users <- getUsers
71 liftIO . putStrLn $ show (length users) ++ " users"
68 liftIO . putStrLn $ show (length users) ++ " users"
72
69
73 user <- liftIO $ do
70 user <- liftIO $ do
74 putStrLn "Enter a valid hackage username"
71 putStrLn "Enter a valid hackage username"
75 T.getLine
72 T.getLine
76− userDetailed <- run (getUser user)
73+ userDetailed <- (getUser user)
77 liftIO . T.putStrLn $ user <> " maintains " <> T.pack (show (length $ groups userDetailed)) <> " packages"
74 liftIO . T.putStrLn $ user <> " maintains " <> T.pack (show (length $ groups userDetailed)) <> " packages"
78−
75+
79− packages <- run getPackages
76+ packages <- getPackages
80 let monadPackages = filter (isMonadPackage . packageName) packages
77 let monadPackages = filter (isMonadPackage . packageName) packages
81 liftIO . putStrLn $ show (length monadPackages) ++ " monad packages"
78 liftIO . putStrLn $ show (length monadPackages) ++ " monad packages"
82
79