Add EmptyForeignAPI and instance HasForeign ... EmptyAPI

This commit is contained in:
David Turner 2017-05-16 10:01:33 +00:00
parent 2cfa71891b
commit fa3f1869f2
2 changed files with 12 additions and 0 deletions

View file

@ -45,6 +45,7 @@ Now let's have the API type(s) and the accompanying datatypes.
``` haskell ``` haskell
type API = "point" :> Get '[JSON] Point type API = "point" :> Get '[JSON] Point
:<|> "books" :> QueryParam "q" Text :> Get '[JSON] (Search Book) :<|> "books" :> QueryParam "q" Text :> Get '[JSON] (Search Book)
:<|> EmptyAPI
type API' = API :<|> Raw type API' = API :<|> Raw
@ -133,6 +134,7 @@ api' = Proxy
server :: Server API server :: Server API
server = randomPoint server = randomPoint
:<|> searchBook :<|> searchBook
:<|> emptyAPIServer
server' :: Server API' server' :: Server API'
server' = server server' = server

View file

@ -187,6 +187,13 @@ instance (HasForeign lang ftype a, HasForeign lang ftype b)
foreignFor lang ftype (Proxy :: Proxy a) req foreignFor lang ftype (Proxy :: Proxy a) req
:<|> foreignFor lang ftype (Proxy :: Proxy b) req :<|> foreignFor lang ftype (Proxy :: Proxy b) req
data EmptyForeignAPI = EmptyForeignAPI
instance HasForeign lang ftype EmptyAPI where
type Foreign ftype EmptyAPI = EmptyForeignAPI
foreignFor Proxy Proxy Proxy _ = EmptyForeignAPI
instance (KnownSymbol sym, HasForeignType lang ftype t, HasForeign lang ftype api) instance (KnownSymbol sym, HasForeignType lang ftype t, HasForeign lang ftype api)
=> HasForeign lang ftype (Capture sym t :> api) where => HasForeign lang ftype (Capture sym t :> api) where
type Foreign ftype (Capture sym t :> api) = Foreign ftype api type Foreign ftype (Capture sym t :> api) = Foreign ftype api
@ -349,6 +356,9 @@ instance HasForeign lang ftype api
class GenerateList ftype reqs where class GenerateList ftype reqs where
generateList :: reqs -> [Req ftype] generateList :: reqs -> [Req ftype]
instance GenerateList ftype EmptyForeignAPI where
generateList _ = []
instance GenerateList ftype (Req ftype) where instance GenerateList ftype (Req ftype) where
generateList r = [r] generateList r = [r]