Skip to content

Commit d99ac9f

Browse files
authored
Merge pull request #124 from paldepind/documentation-additions
Additions to the documentation
2 parents 73dbfbb + b045120 commit d99ac9f

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/Network/HTTP/Affjax.purs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ import Network.HTTP.StatusCode (StatusCode(..))
5151
-- | The result type for Affjax requests.
5252
type 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`.
5457
type 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`.
6478
defaultRequest :: AffjaxRequest
6579
defaultRequest =
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+
-- | ```
214243
affjax :: forall a. Response.Response a -> AffjaxRequest -> Affjax a
215244
affjax rt req = do
216245
res <- AC.fromEffectFnAff $ runFn2 _ajax responseHeader req'

src/Network/HTTP/Affjax/Request.purs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import Web.DOM.Document (Document)
1010
import Web.File.Blob (Blob)
1111
import Web.XHR.FormData (FormData)
1212

13+
-- | Represents data for an HTTP request that will be included in the request
14+
-- | body.
1315
data Request
1416
= ArrayView (forall r. (forall a. A.ArrayView a -> r) -> r)
1517
| Blob Blob

src/Network/HTTP/Affjax/Response.purs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Data.MediaType.Common (applicationJSON)
1010
import Web.DOM.Document (Document)
1111
import Web.File.Blob (Blob)
1212

13+
-- | Used to represent how a HTTP response body should be interpreted.
1314
data Response a
1415
= ArrayBuffer (forall f. f ArrayBuffer -> f a)
1516
| Blob (forall f. f Blob -> f a)
@@ -36,6 +37,8 @@ string = String identity
3637
ignore :: Response Unit
3738
ignore = Ignore identity
3839

40+
-- | Converts a `Response a` into a string representation of the response type
41+
-- | that it represents.
3942
toResponseType :: forall a. Response a -> String
4043
toResponseType =
4144
case _ of

0 commit comments

Comments
 (0)