git.iko.soy/typeable/servant
on master help sign in
Added HasClient and HasForeign instances for NoContentVerb
commit0cbed24f234f0e78e5ea865cc07c217001661263 authorCatherine Galkina <anais94@yandex.ru> dateSat 7 Sep 2019, 18:25 (7 years ago) parent0ec5af1
3 files changed+30−4
servant-client-core/src/Servant/Client/Core/HasClient.hs+15−2 servant-client/test/Servant/ClientTestUtils.hs+2−2 servant-foreign/src/Servant/Foreign/Internal.hs+13
servant-client-core/src/Servant/Client/Core/HasClient.hs+15−2
@@ -50,8 +50,9 @@ import Servant.API
5050 MimeUnrender (mimeUnrender), NoContent (NoContent), QueryFlag,
5151 QueryParam', QueryParams, Raw, ReflectMethod (..), RemoteHost,
5252 ReqBody', SBoolI, Stream, StreamBody', Summary, ToHttpApiData,
53− ToSourceIO (..), Vault, Verb, WithNamedContext, contentType,
54− getHeadersHList, getResponse, toQueryParam, toUrlPiece)
53+ ToSourceIO (..), Vault, Verb, NoContentVerb, WithNamedContext,
54+ contentType, getHeadersHList, getResponse, toQueryParam,
55+ toUrlPiece)
5556import Servant.API.ContentTypes
5657 (contentTypes)
5758import Servant.API.Modifiers
@@ -241,6 +242,18 @@ instance {-# OVERLAPPING #-}
241242
242243 hoistClientMonad _ _ f ma = f ma
243244
245+instance {-# OVERLAPPING #-}
246+ ( RunClient m, ReflectMethod method
247+ ) => HasClient m (NoContentVerb method) where
248+ type Client m (NoContentVerb method)
249+ = m NoContent
250+ clientWithRoute _pm Proxy req = do
251+ _response <- runRequest req { requestMethod = method }
252+ return NoContent
253+ where method = reflectMethod (Proxy :: Proxy method)
254+
255+ hoistClientMonad _ _ f ma = f ma
256+
244257instance {-# OVERLAPPING #-}
245258 -- Note [Non-Empty Content Types]
246259 ( RunClient m, MimeUnrender ct a, BuildHeadersTo ls
servant-client/test/Servant/ClientTestUtils.hs+2−2
@@ -85,7 +85,7 @@ type TestHeaders = '[Header "X-Example1" Int, Header "X-Example2" String]
8585type Api =
8686 Get '[JSON] Person
8787 :<|> "get" :> Get '[JSON] Person
88− :<|> "deleteEmpty" :> DeleteNoContent '[JSON] NoContent
88+ :<|> "deleteEmpty" :> DeleteNoContent
8989 :<|> "capture" :> Capture "name" String :> Get '[JSON,FormUrlEncoded] Person
9090 :<|> "captureAll" :> CaptureAll "names" String :> Get '[JSON] [Person]
9191 :<|> "body" :> ReqBody '[FormUrlEncoded,JSON] Person :> Post '[JSON] Person
@@ -101,7 +101,7 @@ type Api =
101101 ReqBody '[JSON] [(String, [Rational])] :>
102102 Get '[JSON] (String, Maybe Int, Bool, [(String, [Rational])])
103103 :<|> "headers" :> Get '[JSON] (Headers TestHeaders Bool)
104− :<|> "deleteContentType" :> DeleteNoContent '[JSON] NoContent
104+ :<|> "deleteContentType" :> DeleteNoContent
105105 :<|> "redirectWithCookie" :> Raw
106106 :<|> "empty" :> EmptyAPI
107107
servant-foreign/src/Servant/Foreign/Internal.hs+13
@@ -244,6 +244,19 @@ instance (Elem JSON list, HasForeignType lang ftype a, ReflectMethod method)
244244 method = reflectMethod (Proxy :: Proxy method)
245245 methodLC = toLower $ decodeUtf8 method
246246
247+instance (HasForeignType lang ftype NoContent, ReflectMethod method)
248+ => HasForeign lang ftype (NoContentVerb method) where
249+ type Foreign ftype (NoContentVerb method) = Req ftype
250+
251+ foreignFor lang Proxy Proxy req =
252+ req & reqFuncName . _FunctionName %~ (methodLC :)
253+ & reqMethod .~ method
254+ & reqReturnType .~ Just retType
255+ where
256+ retType = typeFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy NoContent)
257+ method = reflectMethod (Proxy :: Proxy method)
258+ methodLC = toLower $ decodeUtf8 method
259+
247260-- | TODO: doesn't taking framing into account.
248261instance (ct ~ JSON, HasForeignType lang ftype a, ReflectMethod method)
249262 => HasForeign lang ftype (Stream method status framing ct a) where