Skip to content

Commit 73dbfbb

Browse files
authored
Merge pull request #123 from slamdata/update-readme
Update readme for current library, add compileable version to tests
2 parents 16c344f + 092ed15 commit 73dbfbb

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/bower_components/
66
/node_modules/
77
/output/
8+
package-lock.json

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,38 @@ You can construct requests with the `affjax` function:
2727
module Main where
2828
2929
import Prelude
30-
import Control.Monad.Eff.Console (log)
31-
import Control.Monad.Eff.Class (liftEff)
32-
import Control.Monad.Aff (launchAff)
30+
31+
import Data.Argonaut.Core as J
3332
import Data.Either (Either(..))
3433
import Data.HTTP.Method (Method(..))
35-
import Network.HTTP.Affjax (affjax, defaultRequest)
34+
import Effect.Aff (launchAff)
35+
import Effect.Class (liftEffect)
36+
import Effect.Console (log)
37+
import Network.HTTP.Affjax as AX
38+
import Network.HTTP.Affjax.Response as AXRes
3639
3740
main = launchAff $ do
38-
res <- affjax $ defaultRequest { url = "/api", method = Left GET }
39-
liftEff $ log $ "GET /api response: " <> res.response
41+
res <- AX.affjax AXRes.json (AX.defaultRequest { url = "/api", method = Left GET })
42+
liftEffect $ log $ "GET /api response: " <> J.stringify res.response
4043
```
4144

4245
(`defaultRequest` is a record value that has all the required fields pre-set for convenient overriding when making a request.)
4346

4447
Or use of a number of helpers for common cases:
4548

4649
```purescript
47-
import Network.HTTP.Affjax (get, post)
50+
import Network.HTTP.Affjax.Request as AXReq
4851
4952
main = launchAff $ do
50-
res1 <- get "/api"
51-
liftEff $ log $ "GET /api response: " <> res1.response
53+
res1 <- AX.get AXRes.json "/api"
54+
liftEffect $ log $ "GET /api response: " <> J.stringify res1.response
5255
53-
res2 <- post "/api" someData
54-
liftEff $ log $ "POST /api response: " <> res2.response
56+
res2 <- AX.post AXRes.json "/api" (AXReq.json (J.fromString "test"))
57+
liftEffect $ log $ "POST /api response: " <> J.stringify res2.response
5558
```
5659

5760
See the module documentation for a full list of these helpers.
5861

59-
When sending data in a request the Requestable class enables automatic conversion into a format that is acceptable for an XHR request. Correspondingly there is a Respondable class for reading data that comes back from the server.
60-
6162
## Module documentation
6263

6364
Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-affjax).

test/DocExamples.purs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Test.DocExamples where
2+
3+
import Prelude
4+
5+
import Data.Argonaut.Core as J
6+
import Data.Either (Either(..))
7+
import Data.HTTP.Method (Method(..))
8+
import Effect.Aff (launchAff)
9+
import Effect.Class (liftEffect)
10+
import Effect.Console (log)
11+
import Network.HTTP.Affjax as AX
12+
import Network.HTTP.Affjax.Request as AXReq
13+
import Network.HTTP.Affjax.Response as AXRes
14+
15+
main = launchAff $ do
16+
res <- AX.affjax AXRes.json (AX.defaultRequest { url = "/api", method = Left GET })
17+
liftEffect $ log $ "GET /api response: " <> J.stringify res.response
18+
19+
main' = launchAff $ do
20+
res1 <- AX.get AXRes.json "/api"
21+
liftEffect $ log $ "GET /api response: " <> J.stringify res1.response
22+
23+
res2 <- AX.post AXRes.json "/api" (AXReq.json (J.fromString "test"))
24+
liftEffect $ log $ "POST /api response: " <> J.stringify res2.response

0 commit comments

Comments
 (0)