git.iko.soy/typeable/servant
on master help sign in
Replace servant-jquery with servant-js in remaining files
commitb88981cf146355819426a74473ff1b4ffce1c213 authorFreezeboy <freezeboy@users.noreply.github.com> dateMon 2 Nov 2015, 19:55 (11 years ago) parent6a4c967
3 files changed+29−24
servant-js/README.md+22−17 servant-js/docs.sh+3−3 servant-js/servant-js.cabal+4−4
servant-js/README.md+22−17
@@ -2,11 +2,14 @@
22
33![servant](https://raw.githubusercontent.com/haskell-servant/servant/master/servant.png)
44
5−This library lets you derive automatically (JQuery based) Javascript functions that let you query each endpoint of a *servant* webservice.
5+This library lets you derive automatically Javascript functions that let you query each endpoint of a *servant* webservice.
6+
7+It contains a powerful system allowing you to generate functions for several frameworks (Angular, AXios, JQuery) as well as
8+vanilla (framework-free) javascript code.
69
710## Example
811
9−Read more about the following example [here](https://github.com/haskell-servant/servant/tree/master/servant-jquery/tree/master/examples#examples).
12+Read more about the following example [here](https://github.com/haskell-servant/servant/tree/master/servant-js/tree/master/examples#examples).
1013
1114``` haskell
1215{-# LANGUAGE DataKinds #-}
@@ -21,7 +24,7 @@ import Data.Proxy
2124import GHC.Generics
2225import Network.Wai.Handler.Warp (run)
2326import Servant
24−import Servant.JQuery
27+import Servant.JS
2528import System.FilePath
2629
2730-- * A simple Counter data type
@@ -48,13 +51,21 @@ currentValue :: MonadIO m => TVar Counter -> m Counter
4851currentValue counter = liftIO $ readTVarIO counter
4952
5053-- * Our API type
51−type TestApi = "counter" :> Post Counter -- endpoint for increasing the counter
52− :<|> "counter" :> Get Counter -- endpoint to get the current value
53− :<|> Raw -- used for serving static files
54+type TestApi = "counter" :> Post '[JSON] Counter -- endpoint for increasing the counter
55+ :<|> "counter" :> Get '[JSON] Counter -- endpoint to get the current value
56+
57+type TestApi' = TestApi -- The API we want a JS handler for
58+ :<|> Raw -- used for serving static files
5459
60+-- this proxy only targets the proper endpoints of our API,
61+-- not the static file serving bit
5562testApi :: Proxy TestApi
5663testApi = Proxy
5764
65+-- this proxy targets everything
66+testApi' :: Proxy TestApi'
67+testApi' = Proxy
68+
5869-- * Server-side handler
5970
6071-- where our static files reside
@@ -65,26 +76,20 @@ www = "examples/www"
6576server :: TVar Counter -> Server TestApi
6677server counter = counterPlusOne counter -- (+1) on the TVar
6778 :<|> currentValue counter -- read the TVar
79+
80+server' :: TVar Counter -> Server TestApi'
81+server counter = server counter
6882 :<|> serveDirectory www -- serve static files
6983
7084runServer :: TVar Counter -- ^ shared variable for the counter
7185 -> Int -- ^ port the server should listen on
7286 -> IO ()
73−runServer var port = run port (serve testApi $ server var)
74−
75−-- * Generating the JQuery code
76−
77−incCounterJS :<|> currentValueJS :<|> _ = jquery testApi
78−
79−writeJS :: FilePath -> [AjaxReq] -> IO ()
80−writeJS fp functions = writeFile fp $
81− concatMap generateJS functions
87+runServer var port = run port (serve testApi' $ server' var)
8288
8389main :: IO ()
8490main = do
8591 -- write the JS code to www/api.js at startup
86− writeJS (www </> "api.js")
87− [ incCounterJS, currentValueJS ]
92+ writeJSForAPI testApi jquery (www </> "api.js")
8893
8994 -- setup a shared counter
9095 cnt <- newCounter
servant-js/docs.sh+3−3
@@ -1,4 +1,4 @@
1−SERVANT_DIR=/tmp/servant-jquery-gh-pages
1+SERVANT_DIR=/tmp/servant-js-gh-pages
22
33# Make a temporary clone
44
@@ -10,7 +10,7 @@ cd $SERVANT_DIR
1010
1111# Make sure to pull the latest
1212
13−git remote add haskell-servant git@github.com:haskell-servant/servant-jquery.git
13+git remote add haskell-servant git@github.com:haskell-servant/servant-js.git
1414
1515git fetch haskell-servant
1616
@@ -36,7 +36,7 @@ cd $SERVANT_DIR
3636
3737rm *
3838rm -rf build
39−mv doc/html/servant-jquery/* .
39+mv doc/html/servant-js/* .
4040rm -r doc/
4141
4242# Add everything
servant-js/servant-js.cabal+4−4
@@ -2,15 +2,15 @@ name: servant-js
22version: 0.5
33synopsis: Automatically derive javascript functions to query servant webservices.
44description:
5− Automatically derive jquery-based javascript functions to query servant webservices.
5+ Automatically derive javascript functions to query servant webservices.
66 .
7− Supports deriving functions using vanilla javascript AJAX requests, Angular or JQuery.
7+ Supports deriving functions using vanilla javascript AJAX requests, Angulari, Axios or JQuery.
88 .
9− You can find an example <https://github.com/haskell-servant/servant/blob/master/servant-jquery/examples/counter.hs here>
9+ You can find an example <https://github.com/haskell-servant/servant/blob/master/servant-js/examples/counter.hs here>
1010 which serves the generated javascript to a webpage that allows you to trigger
1111 webservice calls.
1212 .
13− <https://github.com/haskell-servant/servant/blob/master/servant-jquery/CHANGELOG.md CHANGELOG>
13+ <https://github.com/haskell-servant/servant/blob/master/servant-js/CHANGELOG.md CHANGELOG>
1414license: BSD3
1515license-file: LICENSE
1616author: Alp Mestanogullari