Skip to content

Commit 4f7b83d

Browse files
Update readme in light of affjax driver changes (#172)
* Direct users to driver libraries; drop quickstart stuff * Add note to module docs in case readme is skipped
1 parent 75372f8 commit 4f7b83d

File tree

2 files changed

+13
-58
lines changed

2 files changed

+13
-58
lines changed

README.md

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,64 +7,9 @@
77

88
A library taking advantage of [`aff`](https://github.com/purescript-contrib/purescript-aff) to enable pain-free asynchronous AJAX requests and response handling.
99

10-
## Installation
11-
12-
Install `affjax` with [Spago](https://github.com/purescript/spago):
13-
14-
```sh
15-
spago install affjax
16-
```
17-
18-
If you are using `affjax` in a Node.js setting you will also need to install an additional NPM dependency:
19-
20-
```
21-
npm install xhr2
22-
```
23-
24-
## Quick start
25-
26-
You can construct requests with the `request` function:
27-
28-
```purescript
29-
module Main where
30-
31-
import Prelude
32-
33-
import Affjax as AX
34-
import Affjax.ResponseFormat as ResponseFormat
35-
import Data.Argonaut.Core (stringify, fromString)
36-
import Data.Either (Either(..))
37-
import Data.HTTP.Method (Method(..))
38-
import Effect.Aff (launchAff)
39-
import Effect.Class.Console (log)
40-
41-
main = void $ launchAff $ do
42-
result <- AX.request (AX.defaultRequest { url = "/api", method = Left GET, responseFormat = ResponseFormat.json })
43-
case result of
44-
Left err -> log $ "GET /api response failed to decode: " <> AX.printError err
45-
Right response -> log $ "GET /api response: " <> stringify response.body
46-
```
47-
48-
(`defaultRequest` is a record value that has all the required fields pre-set for convenient overriding when making a request.)
49-
50-
There are also a number of helpers for common `get`, `post`, `put`, `delete`, and `patch` cases:
51-
52-
```purescript
53-
import Affjax.RequestBody as RequestBody
54-
import Data.Maybe (Maybe(..))
55-
import Effect.Aff (launchAff_)
56-
57-
main = launchAff_ do
58-
result1 <- AX.get ResponseFormat.json "/api"
59-
case result1 of
60-
Left err -> log $ "GET /api response failed to decode: " <> AX.printError err
61-
Right response -> log $ "GET /api response: " <> stringify response.body
62-
63-
result2 <- AX.post ResponseFormat.json "/api" (Just (RequestBody.json (fromString "test")))
64-
case result2 of
65-
Left err -> log $ "POST /api response failed to decode: " <> AX.printError err
66-
Right response -> log $ "POST /api response: " <> stringify response.body
67-
```
10+
This library provides types and common functionality that work across environments (e.g. Node, browser), but **it does not work out-of-box**. Rather, use the environment-specific library instead:
11+
- Browser environment: [`purescript-affjax-web`](https://github.com/purescript-contrib/purescript-affjax-web)
12+
- Node environment: [`purescript-affjax-node`](https://github.com/purescript-contrib/purescript-affjax-node)
6813

6914
## Documentation
7015

src/Affjax.purs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
-- | Note: this module is not intended to be used by end-users.
2+
-- | Rather, use the environment-specific library instead:
3+
-- | - [`purescript-affjax-node`](https://github.com/purescript-contrib/purescript-affjax-node)
4+
-- | - [`purescript-affjax-web`](https://github.com/purescript-contrib/purescript-affjax-web)
5+
-- |
6+
-- | You should use this module if you are writing a driver for a specific environment.
7+
-- | See this module's source code for more details.
8+
-- If you want to write a driver for an environment, see the comments
9+
-- for the `AffjaxDriver` type and look at the `node` and `web` libraries
10+
-- (linked above) as examples.
111
module Affjax
212
( Request
313
, defaultRequest

0 commit comments

Comments
 (0)