on master help sign in
Add EmptyForeignAPI and `instance HasForeign ... EmptyAPI`
commitfa3f1869f2e92ffe0145ef877e9cc17e7b4a184d authorDavid Turner <dave.c.turner@gmail.com> dateTue 16 May 2017, 10:01 (9 years ago) parent2cfa718
2 files changed+12
doc/tutorial/Javascript.lhs+2 servant-foreign/src/Servant/Foreign/Internal.hs+10
doc/tutorial/Javascript.lhs+2
@@ -45,6 +45,7 @@ Now let's have the API type(s) and the accompanying datatypes.
4545``` haskell
4646type API = "point" :> Get '[JSON] Point
4747 :<|> "books" :> QueryParam "q" Text :> Get '[JSON] (Search Book)
48+ :<|> EmptyAPI
4849
4950type API' = API :<|> Raw
5051
@@ -133,6 +134,7 @@ api' = Proxy
133134server :: Server API
134135server = randomPoint
135136 :<|> searchBook
137+ :<|> emptyAPIServer
136138
137139server' :: Server API'
138140server' = server
servant-foreign/src/Servant/Foreign/Internal.hs+10
@@ -187,6 +187,13 @@ instance (HasForeign lang ftype a, HasForeign lang ftype b)
187187 foreignFor lang ftype (Proxy :: Proxy a) req
188188 :<|> foreignFor lang ftype (Proxy :: Proxy b) req
189189
190+data EmptyForeignAPI = EmptyForeignAPI
191+
192+instance HasForeign lang ftype EmptyAPI where
193+ type Foreign ftype EmptyAPI = EmptyForeignAPI
194+
195+ foreignFor Proxy Proxy Proxy _ = EmptyForeignAPI
196+
190197instance (KnownSymbol sym, HasForeignType lang ftype t, HasForeign lang ftype api)
191198 => HasForeign lang ftype (Capture sym t :> api) where
192199 type Foreign ftype (Capture sym t :> api) = Foreign ftype api
@@ -349,6 +356,9 @@ instance HasForeign lang ftype api
349356class GenerateList ftype reqs where
350357 generateList :: reqs -> [Req ftype]
351358
359+instance GenerateList ftype EmptyForeignAPI where
360+ generateList _ = []
361+
352362instance GenerateList ftype (Req ftype) where
353363 generateList r = [r]
354364