@@ -51,6 +51,9 @@ import Network.HTTP.StatusCode (StatusCode(..))
51
51
-- | The result type for Affjax requests.
52
52
type Affjax a = Aff (AffjaxResponse a )
53
53
54
+ -- | A record that contains all the information to perform an HTTP request.
55
+ -- | Instead of constructing the record from scratch it is often easier to build
56
+ -- | one based on `defaultRequest`.
54
57
type AffjaxRequest =
55
58
{ method :: Either Method CustomMethod
56
59
, url :: URL
@@ -61,6 +64,17 @@ type AffjaxRequest =
61
64
, withCredentials :: Boolean
62
65
}
63
66
67
+ -- | A record of the type `AffjaxRequest` that has all fields set to default
68
+ -- | values. This record can be used as the as the foundation for constructing
69
+ -- | custom requests.
70
+ -- |
71
+ -- | As an example
72
+ -- |
73
+ -- | ```purescript
74
+ -- | defaultRequest { url = "/api/user", method = Left POST }
75
+ -- | ```
76
+ -- |
77
+ -- | Represents a POST request to the URL `/api/user`.
64
78
defaultRequest :: AffjaxRequest
65
79
defaultRequest =
66
80
{ method: Left GET
@@ -210,7 +224,22 @@ retry policy run req = do
210
224
go failureRef (n + 1 )
211
225
Right resp -> pure resp
212
226
213
- -- | Makes an `Affjax` request.
227
+ -- | Makes an HTTP request. The first argument specifies how the HTTP response
228
+ -- | body should be interpreted.
229
+ -- |
230
+ -- | The example below performs a `GET` request to the URL `/resource`/ and
231
+ -- | interprets the response body as JSON.
232
+ -- |
233
+ -- | ```purescript
234
+ -- | affjax json (defaultRequest { url = "/resource", method = Left GET })
235
+ -- | ```
236
+ -- |
237
+ -- | For common cases helper functions can often be used instead of `affjax` .
238
+ -- | For instance, the above example is equivalent to the following.
239
+ -- |
240
+ -- | ```purescript
241
+ -- | get json "/resource"
242
+ -- | ```
214
243
affjax :: forall a . Response.Response a -> AffjaxRequest -> Affjax a
215
244
affjax rt req = do
216
245
res <- AC .fromEffectFnAff $ runFn2 _ajax responseHeader req'
0 commit comments