@@ -30,13 +30,14 @@ module Javascript where
3030import Control.Monad.IO.Class
3131import Data.Aeson
3232import Data.Proxy
33−import Data.Text (Text)
33+import Data.Text as T (Text)
34+import Data.Text.IO as T (writeFile, readFile)
3435import qualified Data.Text as T
3536import GHC.Generics
3637import Language.Javascript.JQuery
3738import Network.Wai
3839import Servant
39−import Servant.JQuery
40+import Servant.JS
4041import System.Random
4142```
4243
@@ -133,7 +134,7 @@ server' = server
133134 :<|> serveDirectory "tutorial/t9"
134135
135136app :: Application
136−app = serve api' server'
137+app = serve api' EmptyConfig server'
137138```
138139
139140Why two different API types, proxies and servers though? Simply because we don't want to generate javascript functions for the `Raw` part of our API type, so we need a `Proxy` for our API type `API'` without its `Raw` endpoint.
@@ -141,8 +142,8 @@ Why two different API types, proxies and servers though? Simply because we don't
141142Very similarly to how one can derive haskell functions, we can derive the javascript with just a simple function call to `jsForAPI` from `Servant.JQuery`.
142143
143144``` haskell
144−apiJS :: String
145−apiJS = jsForAPI api
145+apiJS :: Text
146+apiJS = jsForAPI api vanillaJS
146147```
147148
148149This `String` contains 2 Javascript functions:
@@ -175,9 +176,9 @@ Right before starting up our server, we will need to write this `String` to a fi
175176``` haskell
176177writeJSFiles :: IO ()
177178writeJSFiles = do
178− writeFile "getting-started/gs9/api.js" apiJS
179− jq <- readFile =<< Language.Javascript.JQuery.file
180− writeFile "getting-started/gs9/jq.js" jq
179+ T.writeFile "getting-started/gs9/api.js" apiJS
180+ jq <- T.readFile =<< Language.Javascript.JQuery.file
181+ T.writeFile "getting-started/gs9/jq.js" jq
181182```
182183
183184And we're good to go. Start the server with `dist/build/tutorial/tutorial 9` and go to `http://localhost:8081/`. Start typing in the name of one of the authors in our database or part of a book title, and check out how long it takes to approximate π using the method mentioned above.