@@ -51,6 +51,9 @@ import Network.HTTP.StatusCode (StatusCode(..))
5151-- | The result type for Affjax requests.
5252type Affjax a = Aff (AffjaxResponse a )
5353
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`.
5457type AffjaxRequest =
5558 { method :: Either Method CustomMethod
5659 , url :: URL
@@ -61,6 +64,17 @@ type AffjaxRequest =
6164 , withCredentials :: Boolean
6265 }
6366
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`.
6478defaultRequest :: AffjaxRequest
6579defaultRequest =
6680 { method: Left GET
@@ -210,7 +224,22 @@ retry policy run req = do
210224 go failureRef (n + 1 )
211225 Right resp -> pure resp
212226
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+ -- | ```
214243affjax :: forall a . Response.Response a -> AffjaxRequest -> Affjax a
215244affjax rt req = do
216245 res <- AC .fromEffectFnAff $ runFn2 _ajax responseHeader req'
0 commit comments