git.iko.soy/typeable/servant
on master help sign in
make BaseUrl an argument to 'client' instead of each function produced by 'client'
8f100a1Alp Mestanogullari
servant-client/src/Servant/Client.hs+116−87
@@ -36,6 +36,8 @@ 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
39import Servant.Common.BaseUrl
41import Servant.Common.BaseUrl
40import Servant.Common.Req
42import Servant.Common.Req
41
43
@@ -62,6 +64,7 @@ class HasClient layout where
62 type Client layout :: *
64 type Client layout :: *
63 clientWithRoute :: Proxy layout -> Req -> Client layout
65 clientWithRoute :: Proxy layout -> Req -> Client layout
64
66
67+type Client layout = Client' layout
65
68
66-- | A client querying function for @a ':<|>' b@ will actually hand you
69-- | A client querying function for @a ':<|>' b@ will actually hand you
67-- one function for querying @a@ and another one for querying @b@,
70-- one function for querying @a@ and another one for querying @b@,
@@ -107,9 +110,10 @@ instance (KnownSymbol capture, ToText a, HasClient sublayout)
107 type Client (Capture capture a :> sublayout) =
110 type Client (Capture capture a :> sublayout) =
108 a -> Client sublayout
111 a -> Client sublayout
109
112
110− clientWithRoute Proxy req val =
113+ clientWithRoute Proxy req baseurl val =
111− clientWithRoute (Proxy :: Proxy sublayout) $
114+ clientWithRoute (Proxy :: Proxy sublayout)
112− appendToPath p req
115+ (appendToPath p req)
116+ baseurl
113
117
114 where p = unpack (toText val)
118 where p = unpack (toText val)
115
119
@@ -122,9 +126,9 @@ instance
122 {-# OVERLAPPABLE #-}
126 {-# OVERLAPPABLE #-}
123#endif
127#endif
124 (MimeUnrender ct a) => HasClient (Delete (ct ': cts) a) where
128 (MimeUnrender ct a) => HasClient (Delete (ct ': cts) a) where
125− type Client (Delete (ct ': cts) a) = BaseUrl -> EitherT ServantError IO a
129+ type Client (Delete (ct ': cts) a) = EitherT ServantError IO a
126− clientWithRoute Proxy req host =
130+ clientWithRoute Proxy req baseurl =
127− snd <$> performRequestCT (Proxy :: Proxy ct) H.methodDelete req [200, 202] host
131+ snd <$> performRequestCT (Proxy :: Proxy ct) H.methodDelete req [200, 202] baseurl
128
132
129-- | If you have a 'Delete xs ()' endpoint, the client expects a 204 No Content
133-- | If you have a 'Delete xs ()' endpoint, the client expects a 204 No Content
130-- HTTP header.
134-- HTTP header.
@@ -133,9 +137,9 @@ instance
133 {-# OVERLAPPING #-}
137 {-# OVERLAPPING #-}
134#endif
138#endif
135 HasClient (Delete (ct ': cts) ()) where
139 HasClient (Delete (ct ': cts) ()) where
136− type Client (Delete (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
140+ type Client (Delete (ct ': cts) ()) = EitherT ServantError IO ()
137− clientWithRoute Proxy req host =
141+ clientWithRoute Proxy req baseurl =
138− void $ performRequestNoBody H.methodDelete req [204] host
142+ void $ performRequestNoBody H.methodDelete req [204] baseurl
139
143
140-- | If you have a 'Delete xs (Headers ls x)' endpoint, the client expects the
144-- | If you have a 'Delete xs (Headers ls x)' endpoint, the client expects the
141-- corresponding headers.
145-- corresponding headers.
@@ -145,14 +149,13 @@ instance
145#endif
149#endif
146 ( MimeUnrender ct a, BuildHeadersTo ls
150 ( MimeUnrender ct a, BuildHeadersTo ls
147 ) => HasClient (Delete (ct ': cts) (Headers ls a)) where
151 ) => HasClient (Delete (ct ': cts) (Headers ls a)) where
148− type Client (Delete (ct ': cts) (Headers ls a)) = BaseUrl -> EitherT ServantError IO (Headers ls a)
152+ type Client (Delete (ct ': cts) (Headers ls a)) = EitherT ServantError IO (Headers ls a)
149− clientWithRoute Proxy req host = do
153+ clientWithRoute Proxy req baseurl = do
150− (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodDelete req [200, 202] host
154+ (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodDelete req [200, 202] baseurl
151 return $ Headers { getResponse = resp
155 return $ Headers { getResponse = resp
152 , getHeadersHList = buildHeadersTo hdrs
156 , getHeadersHList = buildHeadersTo hdrs
153 }
157 }
154
158
155−
156-- | If you have a 'Get' endpoint in your API, the client
159-- | If you have a 'Get' endpoint in your API, the client
157-- side querying function that is created when calling 'client'
160-- side querying function that is created when calling 'client'
158-- will just require an argument that specifies the scheme, host
161-- will just require an argument that specifies the scheme, host
@@ -162,9 +165,9 @@ instance
162 {-# OVERLAPPABLE #-}
165 {-# OVERLAPPABLE #-}
163#endif
166#endif
164 (MimeUnrender ct result) => HasClient (Get (ct ': cts) result) where
167 (MimeUnrender ct result) => HasClient (Get (ct ': cts) result) where
165− type Client (Get (ct ': cts) result) = BaseUrl -> EitherT ServantError IO result
168+ type Client (Get (ct ': cts) result) = EitherT ServantError IO result
166− clientWithRoute Proxy req host =
169+ clientWithRoute Proxy req baseurl =
167− snd <$> performRequestCT (Proxy :: Proxy ct) H.methodGet req [200, 203] host
170+ snd <$> performRequestCT (Proxy :: Proxy ct) H.methodGet req [200, 203] baseurl
168
171
169-- | If you have a 'Get xs ()' endpoint, the client expects a 204 No Content
172-- | If you have a 'Get xs ()' endpoint, the client expects a 204 No Content
170-- HTTP status.
173-- HTTP status.
@@ -173,9 +176,9 @@ instance
173 {-# OVERLAPPING #-}
176 {-# OVERLAPPING #-}
174#endif
177#endif
175 HasClient (Get (ct ': cts) ()) where
178 HasClient (Get (ct ': cts) ()) where
176− type Client (Get (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
179+ type Client (Get (ct ': cts) ()) = EitherT ServantError IO ()
177− clientWithRoute Proxy req host =
180+ clientWithRoute Proxy req baseurl =
178− performRequestNoBody H.methodGet req [204] host
181+ performRequestNoBody H.methodGet req [204] baseurl
179
182
180-- | If you have a 'Get xs (Headers ls x)' endpoint, the client expects the
183-- | If you have a 'Get xs (Headers ls x)' endpoint, the client expects the
181-- corresponding headers.
184-- corresponding headers.
@@ -185,9 +188,9 @@ instance
185#endif
188#endif
186 ( MimeUnrender ct a, BuildHeadersTo ls
189 ( MimeUnrender ct a, BuildHeadersTo ls
187 ) => HasClient (Get (ct ': cts) (Headers ls a)) where
190 ) => HasClient (Get (ct ': cts) (Headers ls a)) where
188− type Client (Get (ct ': cts) (Headers ls a)) = BaseUrl -> EitherT ServantError IO (Headers ls a)
191+ type Client (Get (ct ': cts) (Headers ls a)) = EitherT ServantError IO (Headers ls a)
189− clientWithRoute Proxy req host = do
192+ clientWithRoute Proxy req baseurl = do
190− (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodGet req [200, 203, 204] host
193+ (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodGet req [200, 203, 204] baseurl
191 return $ Headers { getResponse = resp
194 return $ Headers { getResponse = resp
192 , getHeadersHList = buildHeadersTo hdrs
195 , getHeadersHList = buildHeadersTo hdrs
193 }
196 }
@@ -223,9 +226,13 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
223 type Client (Header sym a :> sublayout) =
226 type Client (Header sym a :> sublayout) =
224 Maybe a -> Client sublayout
227 Maybe a -> Client sublayout
225
228
226− clientWithRoute Proxy req mval =
229+ clientWithRoute Proxy req baseurl mval =
227− clientWithRoute (Proxy :: Proxy sublayout) $
230+ clientWithRoute (Proxy :: Proxy sublayout)
231+ (maybe req
228− maybe req (\value -> Servant.Common.Req.addHeader hname value req) mval
232+ (\value -> Servant.Common.Req.addHeader hname value req)
233+ mval
234+ )
235+ baseurl
229
236
230 where hname = symbolVal (Proxy :: Proxy sym)
237 where hname = symbolVal (Proxy :: Proxy sym)
231
238
@@ -238,10 +245,9 @@ instance
238 {-# OVERLAPPABLE #-}
245 {-# OVERLAPPABLE #-}
239#endif
246#endif
240 (MimeUnrender ct a) => HasClient (Post (ct ': cts) a) where
247 (MimeUnrender ct a) => HasClient (Post (ct ': cts) a) where
241− type Client (Post (ct ': cts) a) = BaseUrl -> EitherT ServantError IO a
248+ type Client (Post (ct ': cts) a) = EitherT ServantError IO a
242−
243− clientWithRoute Proxy req uri =
249+ clientWithRoute Proxy req baseurl =
244− snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPost req [200,201] uri
250+ snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPost req [200,201] baseurl
245
251
246-- | If you have a 'Post xs ()' endpoint, the client expects a 204 No Content
252-- | If you have a 'Post xs ()' endpoint, the client expects a 204 No Content
247-- HTTP header.
253-- HTTP header.
@@ -250,9 +256,9 @@ instance
250 {-# OVERLAPPING #-}
256 {-# OVERLAPPING #-}
251#endif
257#endif
252 HasClient (Post (ct ': cts) ()) where
258 HasClient (Post (ct ': cts) ()) where
253− type Client (Post (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
259+ type Client (Post (ct ': cts) ()) = EitherT ServantError IO ()
254− clientWithRoute Proxy req host =
260+ clientWithRoute Proxy req baseurl =
255− void $ performRequestNoBody H.methodPost req [204] host
261+ void $ performRequestNoBody H.methodPost req [204] baseurl
256
262
257-- | If you have a 'Post xs (Headers ls x)' endpoint, the client expects the
263-- | If you have a 'Post xs (Headers ls x)' endpoint, the client expects the
258-- corresponding headers.
264-- corresponding headers.
@@ -262,9 +268,9 @@ instance
262#endif
268#endif
263 ( MimeUnrender ct a, BuildHeadersTo ls
269 ( MimeUnrender ct a, BuildHeadersTo ls
264 ) => HasClient (Post (ct ': cts) (Headers ls a)) where
270 ) => HasClient (Post (ct ': cts) (Headers ls a)) where
265− type Client (Post (ct ': cts) (Headers ls a)) = BaseUrl -> EitherT ServantError IO (Headers ls a)
271+ type Client (Post (ct ': cts) (Headers ls a)) = EitherT ServantError IO (Headers ls a)
266− clientWithRoute Proxy req host = do
272+ clientWithRoute Proxy req baseurl = do
267− (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodPost req [200, 201] host
273+ (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodPost req [200, 201] baseurl
268 return $ Headers { getResponse = resp
274 return $ Headers { getResponse = resp
269 , getHeadersHList = buildHeadersTo hdrs
275 , getHeadersHList = buildHeadersTo hdrs
270 }
276 }
@@ -278,10 +284,9 @@ instance
278 {-# OVERLAPPABLE #-}
284 {-# OVERLAPPABLE #-}
279#endif
285#endif
280 (MimeUnrender ct a) => HasClient (Put (ct ': cts) a) where
286 (MimeUnrender ct a) => HasClient (Put (ct ': cts) a) where
281− type Client (Put (ct ': cts) a) = BaseUrl -> EitherT ServantError IO a
287+ type Client (Put (ct ': cts) a) = EitherT ServantError IO a
282−
283− clientWithRoute Proxy req host =
288+ clientWithRoute Proxy req baseurl =
284− snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPut req [200,201] host
289+ snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPut req [200,201] baseurl
285
290
286-- | If you have a 'Put xs ()' endpoint, the client expects a 204 No Content
291-- | If you have a 'Put xs ()' endpoint, the client expects a 204 No Content
287-- HTTP header.
292-- HTTP header.
@@ -290,9 +295,9 @@ instance
290 {-# OVERLAPPING #-}
295 {-# OVERLAPPING #-}
291#endif
296#endif
292 HasClient (Put (ct ': cts) ()) where
297 HasClient (Put (ct ': cts) ()) where
293− type Client (Put (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
298+ type Client (Put (ct ': cts) ()) = EitherT ServantError IO ()
294− clientWithRoute Proxy req host =
299+ clientWithRoute Proxy req baseurl =
295− void $ performRequestNoBody H.methodPut req [204] host
300+ void $ performRequestNoBody H.methodPut req [204] baseurl
296
301
297-- | If you have a 'Put xs (Headers ls x)' endpoint, the client expects the
302-- | If you have a 'Put xs (Headers ls x)' endpoint, the client expects the
298-- corresponding headers.
303-- corresponding headers.
@@ -302,9 +307,9 @@ instance
302#endif
307#endif
303 ( MimeUnrender ct a, BuildHeadersTo ls
308 ( MimeUnrender ct a, BuildHeadersTo ls
304 ) => HasClient (Put (ct ': cts) (Headers ls a)) where
309 ) => HasClient (Put (ct ': cts) (Headers ls a)) where
305− type Client (Put (ct ': cts) (Headers ls a)) = BaseUrl -> EitherT ServantError IO (Headers ls a)
310+ type Client (Put (ct ': cts) (Headers ls a)) = EitherT ServantError IO (Headers ls a)
306− clientWithRoute Proxy req host = do
311+ clientWithRoute Proxy req baseurl = do
307− (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodPut req [200, 201] host
312+ (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodPut req [200, 201] baseurl
308 return $ Headers { getResponse = resp
313 return $ Headers { getResponse = resp
309 , getHeadersHList = buildHeadersTo hdrs
314 , getHeadersHList = buildHeadersTo hdrs
310 }
315 }
@@ -318,10 +323,9 @@ instance
318 {-# OVERLAPPABLE #-}
323 {-# OVERLAPPABLE #-}
319#endif
324#endif
320 (MimeUnrender ct a) => HasClient (Patch (ct ': cts) a) where
325 (MimeUnrender ct a) => HasClient (Patch (ct ': cts) a) where
321− type Client (Patch (ct ': cts) a) = BaseUrl -> EitherT ServantError IO a
326+ type Client (Patch (ct ': cts) a) = EitherT ServantError IO a
322−
323− clientWithRoute Proxy req host =
327+ clientWithRoute Proxy req baseurl =
324− snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPatch req [200,201] host
328+ snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPatch req [200,201] baseurl
325
329
326-- | If you have a 'Patch xs ()' endpoint, the client expects a 204 No Content
330-- | If you have a 'Patch xs ()' endpoint, the client expects a 204 No Content
327-- HTTP header.
331-- HTTP header.
@@ -330,9 +334,9 @@ instance
330 {-# OVERLAPPING #-}
334 {-# OVERLAPPING #-}
331#endif
335#endif
332 HasClient (Patch (ct ': cts) ()) where
336 HasClient (Patch (ct ': cts) ()) where
333− type Client (Patch (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
337+ type Client (Patch (ct ': cts) ()) = EitherT ServantError IO ()
334− clientWithRoute Proxy req host =
338+ clientWithRoute Proxy req baseurl =
335− void $ performRequestNoBody H.methodPatch req [204] host
339+ void $ performRequestNoBody H.methodPatch req [204] baseurl
336
340
337-- | If you have a 'Patch xs (Headers ls x)' endpoint, the client expects the
341-- | If you have a 'Patch xs (Headers ls x)' endpoint, the client expects the
338-- corresponding headers.
342-- corresponding headers.
@@ -342,9 +346,9 @@ instance
342#endif
346#endif
343 ( MimeUnrender ct a, BuildHeadersTo ls
347 ( MimeUnrender ct a, BuildHeadersTo ls
344 ) => HasClient (Patch (ct ': cts) (Headers ls a)) where
348 ) => HasClient (Patch (ct ': cts) (Headers ls a)) where
345− type Client (Patch (ct ': cts) (Headers ls a)) = BaseUrl -> EitherT ServantError IO (Headers ls a)
349+ type Client (Patch (ct ': cts) (Headers ls a)) = EitherT ServantError IO (Headers ls a)
346− clientWithRoute Proxy req host = do
350+ clientWithRoute Proxy req baseurl = do
347− (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodPatch req [200, 201, 204] host
351+ (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodPatch req [200, 201, 204] baseurl
348 return $ Headers { getResponse = resp
352 return $ Headers { getResponse = resp
349 , getHeadersHList = buildHeadersTo hdrs
353 , getHeadersHList = buildHeadersTo hdrs
350 }
354 }
@@ -381,9 +385,13 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
381 Maybe a -> Client sublayout
385 Maybe a -> Client sublayout
382
386
383 -- if mparam = Nothing, we don't add it to the query string
387 -- if mparam = Nothing, we don't add it to the query string
384− clientWithRoute Proxy req mparam =
388+ clientWithRoute Proxy req baseurl mparam =
385− clientWithRoute (Proxy :: Proxy sublayout) $
389+ clientWithRoute (Proxy :: Proxy sublayout)
390+ (maybe req
386− maybe req (flip (appendToQueryString pname) req . Just) mparamText
391+ (flip (appendToQueryString pname) req . Just)
392+ mparamText
393+ )
394+ baseurl
387
395
388 where pname = cs pname'
396 where pname = cs pname'
389 pname' = symbolVal (Proxy :: Proxy sym)
397 pname' = symbolVal (Proxy :: Proxy sym)
@@ -422,9 +430,13 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
422 type Client (QueryParams sym a :> sublayout) =
430 type Client (QueryParams sym a :> sublayout) =
423 [a] -> Client sublayout
431 [a] -> Client sublayout
424
432
425− clientWithRoute Proxy req paramlist =
433+ clientWithRoute Proxy req baseurl paramlist =
426− clientWithRoute (Proxy :: Proxy sublayout) $
434+ clientWithRoute (Proxy :: Proxy sublayout)
427− foldl' (\ req' -> maybe req' (flip (appendToQueryString pname) req' . Just)) req paramlist'
435+ (foldl' (\ req' -> maybe req' (flip (appendToQueryString pname) req' . Just))
436+ req
437+ paramlist'
438+ )
439+ baseurl
428
440
429 where pname = cs pname'
441 where pname = cs pname'
430 pname' = symbolVal (Proxy :: Proxy sym)
442 pname' = symbolVal (Proxy :: Proxy sym)
@@ -457,11 +469,13 @@ instance (KnownSymbol sym, HasClient sublayout)
457 type Client (QueryFlag sym :> sublayout) =
469 type Client (QueryFlag sym :> sublayout) =
458 Bool -> Client sublayout
470 Bool -> Client sublayout
459
471
460− clientWithRoute Proxy req flag =
472+ clientWithRoute Proxy req baseurl flag =
461− clientWithRoute (Proxy :: Proxy sublayout) $
473+ clientWithRoute (Proxy :: Proxy sublayout)
462− if flag
474+ (if flag
463− then appendToQueryString paramname Nothing req
475+ then appendToQueryString paramname Nothing req
464− else req
476+ else req
477+ )
478+ baseurl
465
479
466 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
480 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
467
481
@@ -497,9 +511,13 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
497 Maybe a -> Client sublayout
511 Maybe a -> Client sublayout
498
512
499 -- if mparam = Nothing, we don't add it to the query string
513 -- if mparam = Nothing, we don't add it to the query string
500− clientWithRoute Proxy req mparam =
514+ clientWithRoute Proxy req baseurl mparam =
501− clientWithRoute (Proxy :: Proxy sublayout) $
515+ clientWithRoute (Proxy :: Proxy sublayout)
516+ (maybe req
502− maybe req (flip (appendToMatrixParams pname . Just) req) mparamText
517+ (flip (appendToMatrixParams pname . Just) req)
518+ mparamText
519+ )
520+ baseurl
503
521
504 where pname = symbolVal (Proxy :: Proxy sym)
522 where pname = symbolVal (Proxy :: Proxy sym)
505 mparamText = fmap (cs . toText) mparam
523 mparamText = fmap (cs . toText) mparam
@@ -537,9 +555,13 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
537 type Client (MatrixParams sym a :> sublayout) =
555 type Client (MatrixParams sym a :> sublayout) =
538 [a] -> Client sublayout
556 [a] -> Client sublayout
539
557
540− clientWithRoute Proxy req paramlist =
558+ clientWithRoute Proxy req baseurl paramlist =
541− clientWithRoute (Proxy :: Proxy sublayout) $
559+ clientWithRoute (Proxy :: Proxy sublayout)
542− foldl' (\ req' value -> maybe req' (flip (appendToMatrixParams pname) req' . Just . cs) value) req paramlist'
560+ (foldl' (\ req' value -> maybe req' (flip (appendToMatrixParams pname) req' . Just . cs) value)
561+ req
562+ paramlist'
563+ )
564+ baseurl
543
565
544 where pname = cs pname'
566 where pname = cs pname'
545 pname' = symbolVal (Proxy :: Proxy sym)
567 pname' = symbolVal (Proxy :: Proxy sym)
@@ -572,22 +594,24 @@ instance (KnownSymbol sym, HasClient sublayout)
572 type Client (MatrixFlag sym :> sublayout) =
594 type Client (MatrixFlag sym :> sublayout) =
573 Bool -> Client sublayout
595 Bool -> Client sublayout
574
596
575− clientWithRoute Proxy req flag =
597+ clientWithRoute Proxy req baseurl flag =
576− clientWithRoute (Proxy :: Proxy sublayout) $
598+ clientWithRoute (Proxy :: Proxy sublayout)
577− if flag
599+ (if flag
578− then appendToMatrixParams paramname Nothing req
600+ then appendToMatrixParams paramname Nothing req
579− else req
601+ else req
602+ )
603+ baseurl
580
604
581 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
605 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
582
606
583-- | Pick a 'Method' and specify where the server you want to query is. You get
607-- | Pick a 'Method' and specify where the server you want to query is. You get
584-- back the full `Response`.
608-- back the full `Response`.
585instance HasClient Raw where
609instance HasClient Raw where
586− type Client Raw = H.Method -> BaseUrl -> EitherT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], Response ByteString)
610+ type Client Raw = H.Method -> EitherT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], Response ByteString)
587
611
588 clientWithRoute :: Proxy Raw -> Req -> Client Raw
612 clientWithRoute :: Proxy Raw -> Req -> Client Raw
589− clientWithRoute Proxy req httpMethod host = do
613+ clientWithRoute Proxy req httpMethod baseurl = do
590− performRequest httpMethod req (const True) host
614+ performRequest httpMethod req (const True) baseurl
591
615
592-- | If you use a 'ReqBody' in one of your endpoints in your API,
616-- | If you use a 'ReqBody' in one of your endpoints in your API,
593-- the corresponding querying function will automatically take
617-- the corresponding querying function will automatically take
@@ -613,18 +637,23 @@ instance (MimeRender ct a, HasClient sublayout)
613 type Client (ReqBody (ct ': cts) a :> sublayout) =
637 type Client (ReqBody (ct ': cts) a :> sublayout) =
614 a -> Client sublayout
638 a -> Client sublayout
615
639
616− clientWithRoute Proxy req body =
640+ clientWithRoute Proxy req baseurl body =
617− clientWithRoute (Proxy :: Proxy sublayout) $ do
641+ clientWithRoute (Proxy :: Proxy sublayout)
618− let ctProxy = Proxy :: Proxy ct
642+ (let ctProxy = Proxy :: Proxy ct
619− setRQBody (mimeRender ctProxy body) (contentType ctProxy) req
643+ in setRQBody (mimeRender ctProxy body)
644+ (contentType ctProxy)
645+ req
646+ )
647+ baseurl
620
648
621-- | Make the querying function append @path@ to the request path.
649-- | Make the querying function append @path@ to the request path.
622instance (KnownSymbol path, HasClient sublayout) => HasClient (path :> sublayout) where
650instance (KnownSymbol path, HasClient sublayout) => HasClient (path :> sublayout) where
623 type Client (path :> sublayout) = Client sublayout
651 type Client (path :> sublayout) = Client sublayout
624
652
625− clientWithRoute Proxy req =
653+ clientWithRoute Proxy req baseurl =
626− clientWithRoute (Proxy :: Proxy sublayout) $
654+ clientWithRoute (Proxy :: Proxy sublayout)
627− appendToPath p req
655+ (appendToPath p req)
656+ baseurl
628
657
629 where p = symbolVal (Proxy :: Proxy path)
658 where p = symbolVal (Proxy :: Proxy path)
630
659
servant-docs/example/greet.hs+1
@@ -8,6 +8,7 @@
8import Control.Lens
8import Control.Lens
9import Data.Aeson
9import Data.Aeson
10import Data.Proxy
10import Data.Proxy
11+import Data.ByteString.Conversion
11import Data.String.Conversions
12import Data.String.Conversions
12import Data.Text (Text)
13import Data.Text (Text)
13import GHC.Generics
14import GHC.Generics
servant-docs/src/Servant/Docs/Internal.hs+25−1
@@ -40,6 +40,7 @@ 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
43import Servant.Utils.Links
44import Servant.Utils.Links
44
45
45import qualified Data.HashMap.Strict as HM
46import qualified Data.HashMap.Strict as HM
@@ -395,7 +396,6 @@ instance ToSample a b => ToSample (Headers ls a) b where
395 toSample _ = toSample (Proxy :: Proxy a)
396 toSample _ = toSample (Proxy :: Proxy a)
396 toSamples _ = toSamples (Proxy :: Proxy a)
397 toSamples _ = toSamples (Proxy :: Proxy a)
397
398
398−
399class AllHeaderSamples ls where
399class AllHeaderSamples ls where
400 allHeaderToSample :: Proxy ls -> [HTTP.Header]
400 allHeaderToSample :: Proxy ls -> [HTTP.Header]
401
401
@@ -684,11 +684,15 @@ 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
687instance
688instance
688#if MIN_VERSION_base(4,8,0)
689#if MIN_VERSION_base(4,8,0)
689 {-# OVERLAPPABLe #-}
690 {-# OVERLAPPABLe #-}
690#endif
691#endif
691 (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
692 (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
692 => HasDocs (Get cts a) where
696 => HasDocs (Get cts a) where
693 docsFor Proxy (endpoint, action) =
697 docsFor Proxy (endpoint, action) =
694 single endpoint' action'
698 single endpoint' action'
@@ -699,11 +703,15 @@ instance
699 t = Proxy :: Proxy cts
703 t = Proxy :: Proxy cts
700 p = Proxy :: Proxy a
704 p = Proxy :: Proxy a
701
705
706+<<<<<<< HEAD
702instance
707instance
703#if MIN_VERSION_base(4,8,0)
708#if MIN_VERSION_base(4,8,0)
704 {-# OVERLAPPING #-}
709 {-# OVERLAPPING #-}
705#endif
710#endif
706 (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts
711 (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
707 , AllHeaderSamples ls , GetHeaders (HList ls) )
715 , AllHeaderSamples ls , GetHeaders (HList ls) )
708 => HasDocs (Get cts (Headers ls a)) where
716 => HasDocs (Get cts (Headers ls a)) where
709 docsFor Proxy (endpoint, action) =
717 docsFor Proxy (endpoint, action) =
@@ -726,11 +734,15 @@ instance (KnownSymbol sym, HasDocs sublayout)
726 action' = over headers (|> headername) action
734 action' = over headers (|> headername) action
727 headername = pack $ symbolVal (Proxy :: Proxy sym)
735 headername = pack $ symbolVal (Proxy :: Proxy sym)
728
736
737+<<<<<<< HEAD
729instance
738instance
730#if MIN_VERSION_base(4,8,0)
739#if MIN_VERSION_base(4,8,0)
731 {-# OVERLAPPABLE #-}
740 {-# OVERLAPPABLE #-}
732#endif
741#endif
733 (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
742 (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
734 => HasDocs (Post cts a) where
746 => HasDocs (Post cts a) where
735 docsFor Proxy (endpoint, action) =
747 docsFor Proxy (endpoint, action) =
736 single endpoint' action'
748 single endpoint' action'
@@ -742,11 +754,15 @@ instance
742 t = Proxy :: Proxy cts
754 t = Proxy :: Proxy cts
743 p = Proxy :: Proxy a
755 p = Proxy :: Proxy a
744
756
757+<<<<<<< HEAD
745instance
758instance
746#if MIN_VERSION_base(4,8,0)
759#if MIN_VERSION_base(4,8,0)
747 {-# OVERLAPPING #-}
760 {-# OVERLAPPING #-}
748#endif
761#endif
749 (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts
762 (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
750 , AllHeaderSamples ls , GetHeaders (HList ls) )
766 , AllHeaderSamples ls , GetHeaders (HList ls) )
751 => HasDocs (Post cts (Headers ls a)) where
767 => HasDocs (Post cts (Headers ls a)) where
752 docsFor Proxy (endpoint, action) =
768 docsFor Proxy (endpoint, action) =
@@ -761,11 +777,15 @@ instance
761 t = Proxy :: Proxy cts
777 t = Proxy :: Proxy cts
762 p = Proxy :: Proxy a
778 p = Proxy :: Proxy a
763
779
780+<<<<<<< HEAD
764instance
781instance
765#if MIN_VERSION_base(4,8,0)
782#if MIN_VERSION_base(4,8,0)
766 {-# OVERLAPPABLE #-}
783 {-# OVERLAPPABLE #-}
767#endif
784#endif
768 (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts)
785 (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
769 => HasDocs (Put cts a) where
789 => HasDocs (Put cts a) where
770 docsFor Proxy (endpoint, action) =
790 docsFor Proxy (endpoint, action) =
771 single endpoint' action'
791 single endpoint' action'
@@ -777,11 +797,15 @@ instance
777 t = Proxy :: Proxy cts
797 t = Proxy :: Proxy cts
778 p = Proxy :: Proxy a
798 p = Proxy :: Proxy a
779
799
800+<<<<<<< HEAD
780instance
801instance
781#if MIN_VERSION_base(4,8,0)
802#if MIN_VERSION_base(4,8,0)
782 {-# OVERLAPPING #-}
803 {-# OVERLAPPING #-}
783#endif
804#endif
784 (ToSample a b, IsNonEmpty cts, AllMimeRender cts b, SupportedTypes cts
805 (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
785 , AllHeaderSamples ls , GetHeaders (HList ls) )
809 , AllHeaderSamples ls , GetHeaders (HList ls) )
786 => HasDocs (Put cts (Headers ls a)) where
810 => HasDocs (Put cts (Headers ls a)) where
787 docsFor Proxy (endpoint, action) =
811 docsFor Proxy (endpoint, action) =
servant/Setupnew file

Binary file not shown.