git.iko.soy/typeable/servant
on master help sign in
remove unsed type and clean up

merge master and fix conflicts

commit7c24c2a5a3c32bba28a7332984790d5306b05238 authorBrandon Martin <zmbmartin@gmail.com> dateFri 8 May 2015, 12:47 (11 years ago) parenteba7d65
5 files changed+30−64
servant-client/src/Servant/Client.hs+20−22 servant-client/test/Servant/ClientSpec.hs+1−5 servant-docs/example/greet.hs−1 servant-docs/src/Servant/Docs/Internal.hs+1−25 servant-examples/hackage/hackage.hs+8−11
servant-client/src/Servant/Client.hs+20−22
@@ -36,8 +36,6 @@ import Network.HTTP.Media
3636import qualified Network.HTTP.Types as H
3737import qualified Network.HTTP.Types.Header as HTTP
3838import Servant.API
39−import Servant.API.ResponseHeaders
40−import Servant.API.ContentTypes
4139import Servant.Common.BaseUrl
4240import Servant.Common.Req
4341
@@ -54,15 +52,15 @@ import Servant.Common.Req
5452-- > getAllBooks :: BaseUrl -> EitherT String IO [Book]
5553-- > postNewBook :: Book -> BaseUrl -> EitherT String IO Book
5654-- > (getAllBooks :<|> postNewBook) = client myApi
57−client :: HasClient layout => Proxy layout -> Client layout
58−client p = clientWithRoute p defReq
55+client :: HasClient layout => Proxy layout -> BaseUrl -> Client layout
56+client p baseurl = clientWithRoute p defReq baseurl
5957
6058-- | This class lets us define how each API combinator
6159-- influences the creation of an HTTP request. It's mostly
6260-- an internal class, you can just use 'client'.
6361class HasClient layout where
6462 type Client' layout :: *
65− clientWithRoute :: Proxy layout -> Req -> Client layout
63+ clientWithRoute :: Proxy layout -> Req -> BaseUrl -> Client' layout
6664
6765type Client layout = Client' layout
6866
@@ -80,10 +78,10 @@ type Client layout = Client' layout
8078-- > postNewBook :: Book -> BaseUrl -> EitherT String IO Book
8179-- > (getAllBooks :<|> postNewBook) = client myApi
8280instance (HasClient a, HasClient b) => HasClient (a :<|> b) where
83− type Client (a :<|> b) = Client a :<|> Client b
84− clientWithRoute Proxy req =
85− clientWithRoute (Proxy :: Proxy a) req :<|>
86− clientWithRoute (Proxy :: Proxy b) req
81+ type Client' (a :<|> b) = Client' a :<|> Client' b
82+ clientWithRoute Proxy req baseurl =
83+ clientWithRoute (Proxy :: Proxy a) req baseurl :<|>
84+ clientWithRoute (Proxy :: Proxy b) req baseurl
8785
8886-- | If you use a 'Capture' in one of your endpoints in your API,
8987-- the corresponding querying function will automatically take
@@ -126,7 +124,7 @@ instance
126124 {-# OVERLAPPABLE #-}
127125#endif
128126 (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
130128 clientWithRoute Proxy req baseurl =
131129 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodDelete req [200, 202] baseurl
132130
@@ -137,7 +135,7 @@ instance
137135 {-# OVERLAPPING #-}
138136#endif
139137 HasClient (Delete (ct ': cts) ()) where
140− type Client (Delete (ct ': cts) ()) = EitherT ServantError IO ()
138+ type Client' (Delete (ct ': cts) ()) = EitherT ServantError IO ()
141139 clientWithRoute Proxy req baseurl =
142140 void $ performRequestNoBody H.methodDelete req [204] baseurl
143141
@@ -149,7 +147,7 @@ instance
149147#endif
150148 ( MimeUnrender ct a, BuildHeadersTo ls
151149 ) => 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)
153151 clientWithRoute Proxy req baseurl = do
154152 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodDelete req [200, 202] baseurl
155153 return $ Headers { getResponse = resp
@@ -165,7 +163,7 @@ instance
165163 {-# OVERLAPPABLE #-}
166164#endif
167165 (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
169167 clientWithRoute Proxy req baseurl =
170168 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodGet req [200, 203] baseurl
171169
@@ -176,7 +174,7 @@ instance
176174 {-# OVERLAPPING #-}
177175#endif
178176 HasClient (Get (ct ': cts) ()) where
179− type Client (Get (ct ': cts) ()) = EitherT ServantError IO ()
177+ type Client' (Get (ct ': cts) ()) = EitherT ServantError IO ()
180178 clientWithRoute Proxy req baseurl =
181179 performRequestNoBody H.methodGet req [204] baseurl
182180
@@ -245,7 +243,7 @@ instance
245243 {-# OVERLAPPABLE #-}
246244#endif
247245 (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
249247 clientWithRoute Proxy req baseurl =
250248 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPost req [200,201] baseurl
251249
@@ -256,7 +254,7 @@ instance
256254 {-# OVERLAPPING #-}
257255#endif
258256 HasClient (Post (ct ': cts) ()) where
259− type Client (Post (ct ': cts) ()) = EitherT ServantError IO ()
257+ type Client' (Post (ct ': cts) ()) = EitherT ServantError IO ()
260258 clientWithRoute Proxy req baseurl =
261259 void $ performRequestNoBody H.methodPost req [204] baseurl
262260
@@ -284,7 +282,7 @@ instance
284282 {-# OVERLAPPABLE #-}
285283#endif
286284 (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
288286 clientWithRoute Proxy req baseurl =
289287 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPut req [200,201] baseurl
290288
@@ -295,7 +293,7 @@ instance
295293 {-# OVERLAPPING #-}
296294#endif
297295 HasClient (Put (ct ': cts) ()) where
298− type Client (Put (ct ': cts) ()) = EitherT ServantError IO ()
296+ type Client' (Put (ct ': cts) ()) = EitherT ServantError IO ()
299297 clientWithRoute Proxy req baseurl =
300298 void $ performRequestNoBody H.methodPut req [204] baseurl
301299
@@ -323,7 +321,7 @@ instance
323321 {-# OVERLAPPABLE #-}
324322#endif
325323 (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
327325 clientWithRoute Proxy req baseurl =
328326 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPatch req [200,201] baseurl
329327
@@ -334,7 +332,7 @@ instance
334332 {-# OVERLAPPING #-}
335333#endif
336334 HasClient (Patch (ct ': cts) ()) where
337− type Client (Patch (ct ': cts) ()) = EitherT ServantError IO ()
335+ type Client' (Patch (ct ': cts) ()) = EitherT ServantError IO ()
338336 clientWithRoute Proxy req baseurl =
339337 void $ performRequestNoBody H.methodPatch req [204] baseurl
340338
@@ -609,8 +607,8 @@ instance (KnownSymbol sym, HasClient sublayout)
609607instance HasClient Raw where
610608 type Client' Raw = H.Method -> EitherT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], Response ByteString)
611609
612− clientWithRoute :: Proxy Raw -> Req -> Client Raw
613− clientWithRoute Proxy req httpMethod baseurl = do
610+ clientWithRoute :: Proxy Raw -> Req -> BaseUrl -> Client' Raw
611+ clientWithRoute Proxy req baseurl httpMethod = do
614612 performRequest httpMethod req (const True) baseurl
615613
616614-- | 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]
8181type Api =
8282 "get" :> Get '[JSON] Person
8383 :<|> "delete" :> Delete '[JSON] ()
84− :<|> "deleteString" :> Delete '[JSON] String
8584 :<|> "capture" :> Capture "name" String :> Get '[JSON,FormUrlEncoded] Person
8685 :<|> "body" :> ReqBody '[FormUrlEncoded,JSON] Person :> Post '[JSON] Person
8786 :<|> "param" :> QueryParam "name" String :> Get '[FormUrlEncoded,JSON] Person
@@ -106,7 +105,6 @@ server :: Application
106105server = serve api (
107106 return alice
108107 :<|> return ()
109− :<|> return "ok"
110108 :<|> (\ name -> return $ Person name 0)
111109 :<|> return
112110 :<|> (\ name -> case name of
@@ -267,14 +265,12 @@ spec = withServer $ \ baseUrl -> do
267265 Left FailureResponse{..} <- runEitherT getResponse
268266 responseStatus `shouldBe` (Status 500 "error message")
269267 mapM_ test $
270− (WrappedApi (Proxy :: Proxy Delete), "Delete") :
268+ (WrappedApi (Proxy :: Proxy (Delete '[JSON] ())), "Delete") :
271269 (WrappedApi (Proxy :: Proxy (Get '[JSON] ())), "Get") :
272270 (WrappedApi (Proxy :: Proxy (Post '[JSON] ())), "Post") :
273271 (WrappedApi (Proxy :: Proxy (Put '[JSON] ())), "Put") :
274272 []
275273
276−type RawRight = (Int, ByteString, MediaType, [HTTP.Header], C.Response ByteString)
277−
278274failSpec :: IO ()
279275failSpec = withFailServer $ \ baseUrl -> do
280276 let getGet :: EitherT ServantError IO Person
servant-docs/example/greet.hs−1
@@ -8,7 +8,6 @@
88import Control.Lens
99import Data.Aeson
1010import Data.Proxy
11−import Data.ByteString.Conversion
1211import Data.String.Conversions
1312import Data.Text (Text)
1413import GHC.Generics
servant-docs/src/Servant/Docs/Internal.hs+1−25
@@ -40,7 +40,6 @@ import GHC.Generics
4040import GHC.TypeLits
4141import Servant.API
4242import Servant.API.ContentTypes
43−import Servant.API.ResponseHeaders
4443import Servant.Utils.Links
4544
4645import qualified Data.HashMap.Strict as HM
@@ -396,6 +395,7 @@ instance ToSample a b => ToSample (Headers ls a) b where
396395 toSample _ = toSample (Proxy :: Proxy a)
397396 toSamples _ = toSamples (Proxy :: Proxy a)
398397
398+
399399class AllHeaderSamples ls where
400400 allHeaderToSample :: Proxy ls -> [HTTP.Header]
401401
@@ -684,15 +684,11 @@ instance
684684 t = Proxy :: Proxy cts
685685 p = Proxy :: Proxy a
686686
687−<<<<<<< HEAD
688687instance
689688#if MIN_VERSION_base(4,8,0)
690689 {-# OVERLAPPABLe #-}
691690#endif
692691 (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
696692 => HasDocs (Get cts a) where
697693 docsFor Proxy (endpoint, action) =
698694 single endpoint' action'
@@ -703,15 +699,11 @@ instance (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
703699 t = Proxy :: Proxy cts
704700 p = Proxy :: Proxy a
705701
706−<<<<<<< HEAD
707702instance
708703#if MIN_VERSION_base(4,8,0)
709704 {-# OVERLAPPING #-}
710705#endif
711706 (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
715707 , AllHeaderSamples ls , GetHeaders (HList ls) )
716708 => HasDocs (Get cts (Headers ls a)) where
717709 docsFor Proxy (endpoint, action) =
@@ -734,15 +726,11 @@ instance (KnownSymbol sym, HasDocs sublayout)
734726 action' = over headers (|> headername) action
735727 headername = pack $ symbolVal (Proxy :: Proxy sym)
736728
737−<<<<<<< HEAD
738729instance
739730#if MIN_VERSION_base(4,8,0)
740731 {-# OVERLAPPABLE #-}
741732#endif
742733 (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
746734 => HasDocs (Post cts a) where
747735 docsFor Proxy (endpoint, action) =
748736 single endpoint' action'
@@ -754,15 +742,11 @@ instance (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
754742 t = Proxy :: Proxy cts
755743 p = Proxy :: Proxy a
756744
757−<<<<<<< HEAD
758745instance
759746#if MIN_VERSION_base(4,8,0)
760747 {-# OVERLAPPING #-}
761748#endif
762749 (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
766750 , AllHeaderSamples ls , GetHeaders (HList ls) )
767751 => HasDocs (Post cts (Headers ls a)) where
768752 docsFor Proxy (endpoint, action) =
@@ -777,15 +761,11 @@ instance (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts
777761 t = Proxy :: Proxy cts
778762 p = Proxy :: Proxy a
779763
780−<<<<<<< HEAD
781764instance
782765#if MIN_VERSION_base(4,8,0)
783766 {-# OVERLAPPABLE #-}
784767#endif
785768 (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
789769 => HasDocs (Put cts a) where
790770 docsFor Proxy (endpoint, action) =
791771 single endpoint' action'
@@ -797,15 +777,11 @@ instance (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
797777 t = Proxy :: Proxy cts
798778 p = Proxy :: Proxy a
799779
800−<<<<<<< HEAD
801780instance
802781#if MIN_VERSION_base(4,8,0)
803782 {-# OVERLAPPING #-}
804783#endif
805784 (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
809785 , AllHeaderSamples ls , GetHeaders (HList ls) )
810786 => HasDocs (Put cts (Headers ls a)) where
811787 docsFor Proxy (endpoint, action) =
servant-examples/hackage/hackage.hs+8−11
@@ -54,29 +54,26 @@ instance FromJSON Package
5454hackageAPI :: Proxy HackageAPI
5555hackageAPI = Proxy
5656
57−getUsers :: BaseUrl -> EitherT ServantError IO [UserSummary]
58−getUser :: Username -> BaseUrl -> EitherT ServantError IO UserDetailed
59−getPackages :: BaseUrl -> EitherT ServantError IO [Package]
60−getUsers :<|> getUser :<|> getPackages = client hackageAPI
61−
62−run :: (BaseUrl -> r) -> r
63−run f = f (BaseUrl Http "hackage.haskell.org" 80)
57+getUsers :: EitherT ServantError IO [UserSummary]
58+getUser :: Username -> EitherT ServantError IO UserDetailed
59+getPackages :: EitherT ServantError IO [Package]
60+getUsers :<|> getUser :<|> getPackages = client hackageAPI $ BaseUrl Http "hackage.haskell.org" 80
6461
6562main :: IO ()
6663main = print =<< uselessNumbers
6764
6865uselessNumbers :: IO (Either ServantError ())
6966uselessNumbers = runEitherT $ do
70− users <- run getUsers
67+ users <- getUsers
7168 liftIO . putStrLn $ show (length users) ++ " users"
7269
7370 user <- liftIO $ do
7471 putStrLn "Enter a valid hackage username"
7572 T.getLine
76− userDetailed <- run (getUser user)
73+ userDetailed <- (getUser user)
7774 liftIO . T.putStrLn $ user <> " maintains " <> T.pack (show (length $ groups userDetailed)) <> " packages"
78−
79− packages <- run getPackages
75+
76+ packages <- getPackages
8077 let monadPackages = filter (isMonadPackage . packageName) packages
8178 liftIO . putStrLn $ show (length monadPackages) ++ " monad packages"
8279