@@ -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
@@ -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
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
67type Client layout = Client' layout
65type Client layout = Client' layout
@@ -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
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 #-}
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
@@ -137,7 +135,7 @@ instance
137 {-# OVERLAPPING #-}
135 {-# OVERLAPPING #-}
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
@@ -149,7 +147,7 @@ instance
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 #-}
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
@@ -176,7 +174,7 @@ instance
176 {-# OVERLAPPING #-}
174 {-# OVERLAPPING #-}
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
@@ -245,7 +243,7 @@ instance
245 {-# OVERLAPPABLE #-}
243 {-# OVERLAPPABLE #-}
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
@@ -256,7 +254,7 @@ instance
256 {-# OVERLAPPING #-}
254 {-# OVERLAPPING #-}
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
@@ -284,7 +282,7 @@ instance
284 {-# OVERLAPPABLE #-}
282 {-# OVERLAPPABLE #-}
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
@@ -295,7 +293,7 @@ instance
295 {-# OVERLAPPING #-}
293 {-# OVERLAPPING #-}
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
@@ -323,7 +321,7 @@ instance
323 {-# OVERLAPPABLE #-}
321 {-# OVERLAPPABLE #-}
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
@@ -334,7 +332,7 @@ instance
334 {-# OVERLAPPING #-}
332 {-# OVERLAPPING #-}
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
@@ -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)
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
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,