@@ -4,7 +4,7 @@ Type safe querying of servant APIs from the browser.
5`servant-client-ghcjs` is much like `servant-client`, as both packages allow you to generate functions that query the endpoints of your servant API. Both packages should feel the same in usage. The big difference lies in how they perform the actual requests. `servant-client` (indirectly) uses your operating system's socket mechanisms, whereas `servant-client-ghcjs` uses your browser's [XHR](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest) mechanisms to send requests.
5`servant-client-ghcjs` is much like `servant-client`, as both packages allow you to generate functions that query the endpoints of your servant API. Both packages should feel the same in usage. The big difference lies in how they perform the actual requests. `servant-client` (indirectly) uses your operating system's socket mechanisms, whereas `servant-client-ghcjs` uses your browser's [XHR](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest) mechanisms to send requests.
7−This guide assumes knowledge of servant. Reading its [documentation](haskell-servant.readthedocs.io) is recommended if you're new to the subject.
7+This guide assumes knowledge of servant. Reading its [documentation](http://haskell-servant.readthedocs.io) is recommended if you're new to the subject.
9## Using servant-client-ghcjs
9## Using servant-client-ghcjs
10`servant-client-ghcjs` should feel familiar if you've worked with `servant-client`.
10`servant-client-ghcjs` should feel familiar if you've worked with `servant-client`.
@@ -14,16 +14,15 @@ Take the following API (taken from the [Querying an API](http://haskell-servant.
15{-# LANGUAGE DataKinds #-}
15{-# LANGUAGE DataKinds #-}
16{-# LANGUAGE DeriveGeneric #-}
16{-# LANGUAGE DeriveGeneric #-}
17−{-# LANGUAGE PackageImports #-}
18{-# LANGUAGE TypeOperators #-}
17{-# LANGUAGE TypeOperators #-}
20module Main where
19module Main where
22−import "aeson" Data.Aeson
21+import Data.Aeson
23−import "base" Data.Proxy
22+import Data.Proxy
24−import "base" GHC.Generics
23+import GHC.Generics
25−import "servant" Servant.API -- To define the API itself
24+import Servant.API -- From the 'servant' package, to define the API itself
26−import "servant-client-ghcjs" Servant.Client.Ghcjs -- To generate client functions
25+import Servant.Client.Ghcjs -- To generate client functions
29 "position" :> Capture "x" Int :> Capture "y" Int :> Get '[JSON] Position
28 "position" :> Capture "x" Int :> Capture "y" Int :> Get '[JSON] Position
@@ -129,7 +128,7 @@ In the example below, the client functions are put in a data type called `APICli
129{-# LANGUAGE TypeApplications #-}
128{-# LANGUAGE TypeApplications #-}
132−import "servant-client-core" Servant.Client.Core
131+import Servant.Client.Core -- From the 'servant-client-core' package
@@ -153,7 +152,7 @@ apiClient = APIClient { .. }
153The call site changes slightly too, as the functions now need to be taken from `apiClient`:
152The call site changes slightly too, as the functions now need to be taken from `apiClient`:
155```haskell
154```haskell
156−import "servant-client-ghcjs" Servant.Client.Ghcjs
155+import Servant.Client.Ghcjs
158main :: IO ()
157main :: IO ()
@@ -161,11 +160,11 @@ main = do
161 print ePos
160 print ePos
164−Here's how the requests would be performed in regular `servant-client`:
163+Here's how the requests would be performed using the regular `servant-client` package:
166```haskell
165```haskell
167−import "servant-client" Servant.Client
166+import Servant.Client
168−import "http-client" Network.HTTP.Client ( newManager, defaultManagerSettings )
167+import Network.HTTP.Client ( newManager, defaultManagerSettings )
170main :: IO ()
169main :: IO ()