git.iko.soy/typeable/servant
on master help sign in
Added HasClient and HasForeign instances for NoContentVerb
0cbed24Catherine Galkina
servant-client-core/src/Servant/Client/Core/HasClient.hs+15−2
@@ -50,8 +50,9 @@ import Servant.API
50 MimeUnrender (mimeUnrender), NoContent (NoContent), QueryFlag,
50 MimeUnrender (mimeUnrender), NoContent (NoContent), QueryFlag,
51 QueryParam', QueryParams, Raw, ReflectMethod (..), RemoteHost,
51 QueryParam', QueryParams, Raw, ReflectMethod (..), RemoteHost,
52 ReqBody', SBoolI, Stream, StreamBody', Summary, ToHttpApiData,
52 ReqBody', SBoolI, Stream, StreamBody', Summary, ToHttpApiData,
53− ToSourceIO (..), Vault, Verb, WithNamedContext, contentType,
53+ ToSourceIO (..), Vault, Verb, NoContentVerb, WithNamedContext,
54− getHeadersHList, getResponse, toQueryParam, toUrlPiece)
54+ contentType, getHeadersHList, getResponse, toQueryParam,
55+ toUrlPiece)
55import Servant.API.ContentTypes
56import Servant.API.ContentTypes
56 (contentTypes)
57 (contentTypes)
57import Servant.API.Modifiers
58import Servant.API.Modifiers
@@ -241,6 +242,18 @@ instance {-# OVERLAPPING #-}
241
242
242 hoistClientMonad _ _ f ma = f ma
243 hoistClientMonad _ _ f ma = f ma
243
244
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+
244instance {-# OVERLAPPING #-}
257instance {-# OVERLAPPING #-}
245 -- Note [Non-Empty Content Types]
258 -- Note [Non-Empty Content Types]
246 ( RunClient m, MimeUnrender ct a, BuildHeadersTo ls
259 ( 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]
85type Api =
85type Api =
86 Get '[JSON] Person
86 Get '[JSON] Person
87 :<|> "get" :> Get '[JSON] Person
87 :<|> "get" :> Get '[JSON] Person
88− :<|> "deleteEmpty" :> DeleteNoContent '[JSON] NoContent
88+ :<|> "deleteEmpty" :> DeleteNoContent
89 :<|> "capture" :> Capture "name" String :> Get '[JSON,FormUrlEncoded] Person
89 :<|> "capture" :> Capture "name" String :> Get '[JSON,FormUrlEncoded] Person
90 :<|> "captureAll" :> CaptureAll "names" String :> Get '[JSON] [Person]
90 :<|> "captureAll" :> CaptureAll "names" String :> Get '[JSON] [Person]
91 :<|> "body" :> ReqBody '[FormUrlEncoded,JSON] Person :> Post '[JSON] Person
91 :<|> "body" :> ReqBody '[FormUrlEncoded,JSON] Person :> Post '[JSON] Person
@@ -101,7 +101,7 @@ type Api =
101 ReqBody '[JSON] [(String, [Rational])] :>
101 ReqBody '[JSON] [(String, [Rational])] :>
102 Get '[JSON] (String, Maybe Int, Bool, [(String, [Rational])])
102 Get '[JSON] (String, Maybe Int, Bool, [(String, [Rational])])
103 :<|> "headers" :> Get '[JSON] (Headers TestHeaders Bool)
103 :<|> "headers" :> Get '[JSON] (Headers TestHeaders Bool)
104− :<|> "deleteContentType" :> DeleteNoContent '[JSON] NoContent
104+ :<|> "deleteContentType" :> DeleteNoContent
105 :<|> "redirectWithCookie" :> Raw
105 :<|> "redirectWithCookie" :> Raw
106 :<|> "empty" :> EmptyAPI
106 :<|> "empty" :> EmptyAPI
107
107
servant-foreign/src/Servant/Foreign/Internal.hs+13
@@ -244,6 +244,19 @@ instance (Elem JSON list, HasForeignType lang ftype a, ReflectMethod method)
244 method = reflectMethod (Proxy :: Proxy method)
244 method = reflectMethod (Proxy :: Proxy method)
245 methodLC = toLower $ decodeUtf8 method
245 methodLC = toLower $ decodeUtf8 method
246
246
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+
247-- | TODO: doesn't taking framing into account.
260-- | TODO: doesn't taking framing into account.
248instance (ct ~ JSON, HasForeignType lang ftype a, ReflectMethod method)
261instance (ct ~ JSON, HasForeignType lang ftype a, ReflectMethod method)
249 => HasForeign lang ftype (Stream method status framing ct a) where
262 => HasForeign lang ftype (Stream method status framing ct a) where