@@ -33,7 +33,9 @@ import Control.Arrow
3333import Control.Monad
3434 (unless)
3535import qualified Data.ByteString as BS
36−import qualified Data.ByteString.Lazy as BL
36+import Data.ByteString.Builder
37+ (toLazyByteString)
38+import qualified Data.ByteString.Lazy as BL
3739import Data.Either
3840 (partitionEithers)
3941import Data.Constraint (Dict(..))
@@ -63,7 +65,7 @@ import Data.Text
6365import Data.Proxy
6466 (Proxy (Proxy))
6567import GHC.TypeLits
66− (KnownNat, KnownSymbol, TypeError, symbolVal)
68+ (KnownSymbol, symbolVal)
6769import Network.HTTP.Types
6870 (Status)
6971import qualified Network.HTTP.Types as H
@@ -84,12 +86,9 @@ import Servant.API.Generic
8486 , GenericServant, toServant, fromServant)
8587import Servant.API.ContentTypes
8688 (contentTypes, AllMime (allMime), AllMimeUnrender (allMimeUnrender))
87−import Servant.API.Status
88− (statusFromNat)
8989import Servant.API.TypeLevel (FragmentUnique, AtLeastOneFragment)
9090import Servant.API.Modifiers
9191 (FoldRequired, RequiredArgument, foldRequiredArgument)
92−import Servant.API.TypeErrors
9392import Servant.API.UVerb
9493 (HasStatus, HasStatuses (Statuses, statuses), UVerb, Union, Unique, inject, statusOf, foldMapUnion, matchUnion)
9594
@@ -208,7 +207,7 @@ instance (KnownSymbol capture, ToHttpApiData a, HasClient m api)
208207 clientWithRoute pm (Proxy :: Proxy api)
209208 (appendToPath p req)
210209
211− where p = toEncodedUrlPiece val
210+ where p = (toUrlPiece val)
212211
213212 hoistClientMonad pm _ f cl = \a ->
214213 hoistClientMonad pm (Proxy :: Proxy api) f (cl a)
@@ -243,7 +242,7 @@ instance (KnownSymbol capture, ToHttpApiData a, HasClient m sublayout)
243242 clientWithRoute pm (Proxy :: Proxy sublayout)
244243 (foldl' (flip appendToPath) req ps)
245244
246− where ps = map toEncodedUrlPiece vals
245+ where ps = map (toUrlPiece) vals
247246
248247 hoistClientMonad pm _ f cl = \as ->
249248 hoistClientMonad pm (Proxy :: Proxy sublayout) f (cl as)
@@ -251,11 +250,10 @@ instance (KnownSymbol capture, ToHttpApiData a, HasClient m sublayout)
251250instance {-# OVERLAPPABLE #-}
252251 -- Note [Non-Empty Content Types]
253252 ( RunClient m, MimeUnrender ct a, ReflectMethod method, cts' ~ (ct ': cts)
254− , KnownNat status
255253 ) => HasClient m (Verb method status cts' a) where
256254 type Client m (Verb method status cts' a) = m a
257255 clientWithRoute _pm Proxy req = do
258− response <- runRequestAcceptStatus (Just [status]) req
256+ response <- runRequest req
259257 { requestAccept = fromList $ toList accept
260258 , requestMethod = method
261259 }
@@ -263,20 +261,18 @@ instance {-# OVERLAPPABLE #-}
263261 where
264262 accept = contentTypes (Proxy :: Proxy ct)
265263 method = reflectMethod (Proxy :: Proxy method)
266− status = statusFromNat (Proxy :: Proxy status)
267264
268265 hoistClientMonad _ _ f ma = f ma
269266
270267instance {-# OVERLAPPING #-}
271− ( RunClient m, ReflectMethod method, KnownNat status
268+ ( RunClient m, ReflectMethod method
272269 ) => HasClient m (Verb method status cts NoContent) where
273270 type Client m (Verb method status cts NoContent)
274271 = m NoContent
275272 clientWithRoute _pm Proxy req = do
276− _response <- runRequestAcceptStatus (Just [status]) req { requestMethod = method }
273+ _response <- runRequest req { requestMethod = method }
277274 return NoContent
278275 where method = reflectMethod (Proxy :: Proxy method)
279− status = statusFromNat (Proxy :: Proxy status)
280276
281277 hoistClientMonad _ _ f ma = f ma
282278
@@ -293,13 +289,13 @@ instance (RunClient m, ReflectMethod method) =>
293289
294290instance {-# OVERLAPPING #-}
295291 -- Note [Non-Empty Content Types]
296− ( RunClient m, MimeUnrender ct a, BuildHeadersTo ls, KnownNat status
292+ ( RunClient m, MimeUnrender ct a, BuildHeadersTo ls
297293 , ReflectMethod method, cts' ~ (ct ': cts)
298294 ) => HasClient m (Verb method status cts' (Headers ls a)) where
299295 type Client m (Verb method status cts' (Headers ls a))
300296 = m (Headers ls a)
301297 clientWithRoute _pm Proxy req = do
302− response <- runRequestAcceptStatus (Just [status]) req
298+ response <- runRequest req
303299 { requestMethod = method
304300 , requestAccept = fromList $ toList accept
305301 }
@@ -307,26 +303,22 @@ instance {-# OVERLAPPING #-}
307303 return $ Headers { getResponse = val
308304 , getHeadersHList = buildHeadersTo . toList $ responseHeaders response
309305 }
310− where
311− method = reflectMethod (Proxy :: Proxy method)
312− accept = contentTypes (Proxy :: Proxy ct)
313− status = statusFromNat (Proxy :: Proxy status)
306+ where method = reflectMethod (Proxy :: Proxy method)
307+ accept = contentTypes (Proxy :: Proxy ct)
314308
315309 hoistClientMonad _ _ f ma = f ma
316310
317311instance {-# OVERLAPPING #-}
318− ( RunClient m, BuildHeadersTo ls, ReflectMethod method, KnownNat status
312+ ( RunClient m, BuildHeadersTo ls, ReflectMethod method
319313 ) => HasClient m (Verb method status cts (Headers ls NoContent)) where
320314 type Client m (Verb method status cts (Headers ls NoContent))
321315 = m (Headers ls NoContent)
322316 clientWithRoute _pm Proxy req = do
323− response <- runRequestAcceptStatus (Just [status]) req { requestMethod = method }
317+ let method = reflectMethod (Proxy :: Proxy method)
318+ response <- runRequest req { requestMethod = method }
324319 return $ Headers { getResponse = NoContent
325320 , getHeadersHList = buildHeadersTo . toList $ responseHeaders response
326321 }
327− where
328− method = reflectMethod (Proxy :: Proxy method)
329− status = statusFromNat (Proxy :: Proxy status)
330322
331323 hoistClientMonad _ _ f ma = f ma
332324
@@ -569,7 +561,7 @@ instance (KnownSymbol sym, ToHttpApiData a, HasClient m api, SBoolI (FoldRequire
569561 (Proxy :: Proxy mods) add (maybe req add) mparam
570562 where
571563 add :: a -> Request
572− add param = appendToQueryString pname (Just $ encodeQueryParamValue param) req
564+ add param = appendToQueryString pname (Just $ encodeQueryParam param) req
573565
574566 pname :: Text
575567 pname = pack $ symbolVal (Proxy :: Proxy sym)
@@ -577,6 +569,9 @@ instance (KnownSymbol sym, ToHttpApiData a, HasClient m api, SBoolI (FoldRequire
577569 hoistClientMonad pm _ f cl = \arg ->
578570 hoistClientMonad pm (Proxy :: Proxy api) f (cl arg)
579571
572+encodeQueryParam :: ToHttpApiData a => a -> BS.ByteString
573+encodeQueryParam = BL.toStrict . toLazyByteString . toEncodedUrlPiece
574+
580575-- | If you use a 'QueryParams' in one of your endpoints in your API,
581576-- the corresponding querying function will automatically take
582577-- an additional argument, a list of values of the type specified
@@ -618,7 +613,7 @@ instance (KnownSymbol sym, ToHttpApiData a, HasClient m api)
618613 )
619614
620615 where pname = pack $ symbolVal (Proxy :: Proxy sym)
621− paramlist' = map (Just . encodeQueryParamValue) paramlist
616+ paramlist' = map (Just . encodeQueryParam) paramlist
622617
623618 hoistClientMonad pm _ f cl = \as ->
624619 hoistClientMonad pm (Proxy :: Proxy api) f (cl as)
@@ -740,7 +735,7 @@ instance (KnownSymbol path, HasClient m api) => HasClient m (path :> api) where
740735 clientWithRoute pm (Proxy :: Proxy api)
741736 (appendToPath p req)
742737
743− where p = toEncodedUrlPiece $ pack $ symbolVal (Proxy :: Proxy path)
738+ where p = pack $ symbolVal (Proxy :: Proxy path)
744739
745740 hoistClientMonad pm _ f cl = hoistClientMonad pm (Proxy :: Proxy api) f cl
746741
@@ -789,7 +784,7 @@ instance ( HasClient m api
789784
790785-- | Ignore @'Fragment'@ in client functions.
791786-- See <https://ietf.org/rfc/rfc2616.html#section-15.1.3> for more details.
792−--
787+--
793788-- Example:
794789--
795790-- > type MyApi = "books" :> Fragment Text :> Get '[JSON] [Book]
@@ -806,7 +801,7 @@ instance (AtLeastOneFragment api, FragmentUnique (Fragment a :> api), HasClient
806801
807802 type Client m (Fragment a :> api) = Client m api
808803
809− clientWithRoute pm _ = clientWithRoute pm (Proxy :: Proxy api)
804+ clientWithRoute pm _ = clientWithRoute pm (Proxy :: Proxy api)
810805
811806 hoistClientMonad pm _ = hoistClientMonad pm (Proxy :: Proxy api)
812807
@@ -874,7 +869,7 @@ infixl 2 /:
874869--
875870-- Example:
876871--
877−-- @
872+-- @@
878873-- type Api = NamedRoutes RootApi
879874--
880875-- data RootApi mode = RootApi
@@ -895,7 +890,7 @@ infixl 2 /:
895890--
896891-- endpointClient :: ClientM Person
897892-- endpointClient = client // subApi // endpoint
898−-- @
893+-- @@
899894(//) :: a -> (a -> b) -> b
900895x // f = f x
901896
@@ -906,7 +901,7 @@ x // f = f x
906901--
907902-- Example:
908903--
909−-- @
904+-- @@
910905-- type Api = NamedRoutes RootApi
911906--
912907-- data RootApi mode = RootApi
@@ -931,7 +926,7 @@ x // f = f x
931926--
932927-- endpointClient :: ClientM Person
933928-- endpointClient = client // subApi /: "foobar123" // endpoint
934−-- @
929+-- @@
935930(/:) :: (a -> b -> c) -> b -> a -> c
936931(/:) = flip
937932
@@ -975,19 +970,3 @@ decodedAs response ct = do
975970 Right val -> return val
976971 where
977972 accept = toList $ contentTypes ct
978−
979−-------------------------------------------------------------------------------
980−-- Custom type errors
981−-------------------------------------------------------------------------------
982−
983−-- Erroring instance for HasClient' when a combinator is not fully applied
984−instance (RunClient m, TypeError (PartialApplication HasClient arr)) => HasClient m ((arr :: a -> b) :> sub)
985− where
986− type Client m (arr :> sub) = TypeError (PartialApplication HasClient arr)
987− clientWithRoute _ _ _ = error "unreachable"
988− hoistClientMonad _ _ _ _ = error "unreachable"
989−
990−-- Erroring instances for 'HasClient' for unknown API combinators
991−instance {-# OVERLAPPABLE #-} (RunClient m, TypeError (NoInstanceForSub (HasClient m) ty)) => HasClient m (ty :> sub)
992−
993−instance {-# OVERLAPPABLE #-} (RunClient m, TypeError (NoInstanceFor (HasClient m api))) => HasClient m api