@@ -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,