Package maintainers and Hackage trustees are allowed to edit certain bits
of package metadata after a release, without uploading a new tarball.
Note that the tarball itself is never changed, just the metadata that is
stored separately. For more information about metadata revisions, please
refer to the
Hackage Metadata Revisions FAQ.
No. |
Time |
User |
SHA256 |
-r2 (servant-jquery-0.2-r2) |
2014-12-09T14:45:07Z |
AlpMestanogullari |
bae311d2035a00445a89f28e5be959a55acf7402dc59c857c6714c653e05607e
|
|
Changed description
from Automatically derive jquery-based javascript functions to query servant webservices.
Example below that serves the generated javascript to a webpage that lets you
trigger webservice calls.
> import Control.Concurrent.STM
> import Control.Monad.IO.Class
> import Data.Aeson
> import Data.Proxy
> import GHC.Generics
> import Network.Wai.Handler.Warp (run)
> import Servant
> import Servant.JQuery
> import System.FilePath
>
> -- * A simple Counter data type
> newtype Counter = Counter { value :: Int }
> deriving (Generic, Show, Num)
>
> instance ToJSON Counter
>
> -- * Shared counter operations
>
> -- Creating a counter that starts from 0
> newCounter :: IO (TVar Counter)
> newCounter = newTVarIO 0
>
> -- Increasing the counter by 1
> counterPlusOne :: MonadIO m => TVar Counter -> m Counter
> counterPlusOne counter = liftIO . atomically $ do
> oldValue <- readTVar counter
> let newValue = oldValue + 1
> writeTVar counter newValue
> return newValue
>
> currentValue :: MonadIO m => TVar Counter -> m Counter
> currentValue counter = liftIO $ readTVarIO counter
>
> -- * Our API type
> type TestApi = "counter" :> Post Counter -- endpoint for increasing the counter
> :<|> "counter" :> Get Counter -- endpoint to get the current value
> :<|> Raw -- used for serving static files
>
> testApi :: Proxy TestApi
> testApi = Proxy
>
> -- * Server-side handler
>
> -- where our static files reside
> www :: FilePath
> www = "examples/www"
>
> -- defining handlers
> server :: TVar Counter -> Server TestApi
> server counter = counterPlusOne counter -- (+1) on the TVar
> :<|> currentValue counter -- read the TVar
> :<|> serveDirectory www -- serve static files
>
> runServer :: TVar Counter -- ^ shared variable for the counter
> -> Int -- ^ port the server should listen on
> -> IO ()
> runServer var port = run port (serve testApi $ server var)
>
> -- * Generating the JQuery code
>
> incCounterJS :<|> currentValueJS :<|> _ = jquery testApi
>
> writeJS :: FilePath -> [AjaxReq] -> IO ()
> writeJS fp functions = writeFile fp $
> concatMap generateJS functions
>
> main :: IO ()
> main = do
> -- write the JS code to www/api.js at startup
> writeJS (www </> "api.js")
> [ incCounterJS, currentValueJS ]
>
> -- setup a shared counter
> cnt <- newCounter
>
> -- listen to requests on port 8080
> runServer cnt 8080
to Automatically derive jquery-based javascript functions to query servant webservices.
Example <https://github.com/haskell-servant/servant-jquery/blob/master/examples/counter.hs here> that serves the generated javascript to a webpage that lets you
trigger webservice calls.
|
-r1 (servant-jquery-0.2-r1) |
2014-12-09T14:43:03Z |
AlpMestanogullari |
8241836c014ca4a6885635a929b755ac1ceef91cc0ff734ac200a35cdcc4b8c3
|
|
Changed description
from Automatically derive jquery-based javascript functions to query servant webservices.
Example below that serves the generated javascript to a webpage that lets you
trigger webservice calls.
> {-# LANGUAGE DataKinds #-}
> {-# LANGUAGE TypeOperators #-}
> {-# LANGUAGE DeriveGeneric #-}
> {-# LANGUAGE GeneralizedNewtypeDeriving #-}
>
> import Control.Concurrent.STM
> import Control.Monad.IO.Class
> import Data.Aeson
> import Data.Proxy
> import GHC.Generics
> import Network.Wai.Handler.Warp (run)
> import Servant
> import Servant.JQuery
> import System.FilePath
>
> -- * A simple Counter data type
> newtype Counter = Counter { value :: Int }
> deriving (Generic, Show, Num)
>
> instance ToJSON Counter
>
> -- * Shared counter operations
>
> -- Creating a counter that starts from 0
> newCounter :: IO (TVar Counter)
> newCounter = newTVarIO 0
>
> -- Increasing the counter by 1
> counterPlusOne :: MonadIO m => TVar Counter -> m Counter
> counterPlusOne counter = liftIO . atomically $ do
> oldValue <- readTVar counter
> let newValue = oldValue + 1
> writeTVar counter newValue
> return newValue
>
> currentValue :: MonadIO m => TVar Counter -> m Counter
> currentValue counter = liftIO $ readTVarIO counter
>
> -- * Our API type
> type TestApi = "counter" :> Post Counter -- endpoint for increasing the counter
> :<|> "counter" :> Get Counter -- endpoint to get the current value
> :<|> Raw -- used for serving static files
>
> testApi :: Proxy TestApi
> testApi = Proxy
>
> -- * Server-side handler
>
> -- where our static files reside
> www :: FilePath
> www = "examples/www"
>
> -- defining handlers
> server :: TVar Counter -> Server TestApi
> server counter = counterPlusOne counter -- (+1) on the TVar
> :<|> currentValue counter -- read the TVar
> :<|> serveDirectory www -- serve static files
>
> runServer :: TVar Counter -- ^ shared variable for the counter
> -> Int -- ^ port the server should listen on
> -> IO ()
> runServer var port = run port (serve testApi $ server var)
>
> -- * Generating the JQuery code
>
> incCounterJS :<|> currentValueJS :<|> _ = jquery testApi
>
> writeJS :: FilePath -> [AjaxReq] -> IO ()
> writeJS fp functions = writeFile fp $
> concatMap generateJS functions
>
> main :: IO ()
> main = do
> -- write the JS code to www/api.js at startup
> writeJS (www </> "api.js")
> [ incCounterJS, currentValueJS ]
>
> -- setup a shared counter
> cnt <- newCounter
>
> -- listen to requests on port 8080
> runServer cnt 8080
to Automatically derive jquery-based javascript functions to query servant webservices.
Example below that serves the generated javascript to a webpage that lets you
trigger webservice calls.
> import Control.Concurrent.STM
> import Control.Monad.IO.Class
> import Data.Aeson
> import Data.Proxy
> import GHC.Generics
> import Network.Wai.Handler.Warp (run)
> import Servant
> import Servant.JQuery
> import System.FilePath
>
> -- * A simple Counter data type
> newtype Counter = Counter { value :: Int }
> deriving (Generic, Show, Num)
>
> instance ToJSON Counter
>
> -- * Shared counter operations
>
> -- Creating a counter that starts from 0
> newCounter :: IO (TVar Counter)
> newCounter = newTVarIO 0
>
> -- Increasing the counter by 1
> counterPlusOne :: MonadIO m => TVar Counter -> m Counter
> counterPlusOne counter = liftIO . atomically $ do
> oldValue <- readTVar counter
> let newValue = oldValue + 1
> writeTVar counter newValue
> return newValue
>
> currentValue :: MonadIO m => TVar Counter -> m Counter
> currentValue counter = liftIO $ readTVarIO counter
>
> -- * Our API type
> type TestApi = "counter" :> Post Counter -- endpoint for increasing the counter
> :<|> "counter" :> Get Counter -- endpoint to get the current value
> :<|> Raw -- used for serving static files
>
> testApi :: Proxy TestApi
> testApi = Proxy
>
> -- * Server-side handler
>
> -- where our static files reside
> www :: FilePath
> www = "examples/www"
>
> -- defining handlers
> server :: TVar Counter -> Server TestApi
> server counter = counterPlusOne counter -- (+1) on the TVar
> :<|> currentValue counter -- read the TVar
> :<|> serveDirectory www -- serve static files
>
> runServer :: TVar Counter -- ^ shared variable for the counter
> -> Int -- ^ port the server should listen on
> -> IO ()
> runServer var port = run port (serve testApi $ server var)
>
> -- * Generating the JQuery code
>
> incCounterJS :<|> currentValueJS :<|> _ = jquery testApi
>
> writeJS :: FilePath -> [AjaxReq] -> IO ()
> writeJS fp functions = writeFile fp $
> concatMap generateJS functions
>
> main :: IO ()
> main = do
> -- write the JS code to www/api.js at startup
> writeJS (www </> "api.js")
> [ incCounterJS, currentValueJS ]
>
> -- setup a shared counter
> cnt <- newCounter
>
> -- listen to requests on port 8080
> runServer cnt 8080
|
-r0 (servant-jquery-0.2-r0) |
2014-12-09T14:40:05Z |
AlpMestanogullari |
143e9e20de94f7226ad1aa5fe2bee108f9883adc615be3baedfe3c3bcb6e9b14
|
|
|