Module

Network.HTTP.Affjax

Package
purescript-affjax
Repository
slamdata/purescript-affjax

#Affjax Source

type Affjax a = Aff (AffjaxResponse a)

The result type for Affjax requests.

#AffjaxRequest Source

type AffjaxRequest = { content :: Maybe Request, headers :: Array RequestHeader, method :: Either Method CustomMethod, password :: Maybe String, url :: URL, username :: Maybe String, withCredentials :: Boolean }

A record that contains all the information to perform an HTTP request. Instead of constructing the record from scratch it is often easier to build one based on defaultRequest.

#defaultRequest Source

defaultRequest :: AffjaxRequest

A record of the type AffjaxRequest that has all fields set to default values. This record can be used as the as the foundation for constructing custom requests.

As an example

defaultRequest { url = "/api/user", method = Left POST }

Represents a POST request to the URL /api/user.

#AffjaxResponse Source

type AffjaxResponse a = { headers :: Array ResponseHeader, response :: a, status :: StatusCode, statusText :: String }

The type of records that will be received as an Affjax response.

#URL Source

type URL = String

Type alias for URL strings to aid readability of types.

#affjax Source

affjax :: forall a. Response a -> AffjaxRequest -> Affjax a

Makes an HTTP request. The first argument specifies how the HTTP response body should be interpreted.

The example below performs a GET request to the URL /resource/ and interprets the response body as JSON.

affjax json (defaultRequest { url = "/resource", method = Left GET })

For common cases helper functions can often be used instead of affjax . For instance, the above example is equivalent to the following.

get json "/resource"

#get Source

get :: forall a. Response a -> URL -> Affjax a

Makes a GET request to the specified URL.

#post Source

post :: forall a. Response a -> URL -> Request -> Affjax a

Makes a POST request to the specified URL, sending data.

#post_ Source

post_ :: URL -> Request -> Affjax Unit

Makes a POST request to the specified URL, sending data and ignoring the response.

#post' Source

post' :: forall a. Response a -> URL -> Maybe Request -> Affjax a

Makes a POST request to the specified URL with the option to send data.

#post_' Source

post_' :: URL -> Maybe Request -> Affjax Unit

Makes a POST request to the specified URL with the option to send data, and ignores the response.

#put Source

put :: forall a. Response a -> URL -> Request -> Affjax a

Makes a PUT request to the specified URL, sending data.

#put_ Source

put_ :: URL -> Request -> Affjax Unit

Makes a PUT request to the specified URL, sending data and ignoring the response.

#put' Source

put' :: forall a. Response a -> URL -> Maybe Request -> Affjax a

Makes a PUT request to the specified URL with the option to send data.

#put_' Source

put_' :: URL -> Maybe Request -> Affjax Unit

Makes a PUT request to the specified URL with the option to send data, and ignores the response.

#delete Source

delete :: forall a. Response a -> URL -> Affjax a

Makes a DELETE request to the specified URL.

#delete_ Source

delete_ :: URL -> Affjax Unit

Makes a DELETE request to the specified URL and ignores the response.

#patch Source

patch :: forall a. Response a -> URL -> Request -> Affjax a

Makes a PATCH request to the specified URL, sending data.

#patch_ Source

patch_ :: URL -> Request -> Affjax Unit

Makes a PATCH request to the specified URL, sending data and ignoring the response.

#patch' Source

patch' :: forall a. Response a -> URL -> Maybe Request -> Affjax a

Makes a PATCH request to the specified URL with the option to send data.

#patch_' Source

patch_' :: URL -> Maybe Request -> Affjax Unit

Makes a PATCH request to the specified URL with the option to send data, and ignores the response.

#RetryDelayCurve Source

type RetryDelayCurve = Int -> Milliseconds

A sequence of retry delays, in milliseconds.

#RetryPolicy Source

type RetryPolicy = { delayCurve :: RetryDelayCurve, shouldRetryWithStatusCode :: StatusCode -> Boolean, timeout :: Maybe Milliseconds }

Expresses a policy for retrying Affjax requests with backoff.

#defaultRetryPolicy Source

defaultRetryPolicy :: RetryPolicy

A sensible default for retries: no timeout, maximum delay of 30s, initial delay of 0.1s, exponential backoff, and no status code triggers a retry.

#retry Source

retry :: forall a. RetryPolicy -> (AffjaxRequest -> Affjax a) -> AffjaxRequest -> Affjax a

Retry a request using a RetryPolicy. After the timeout, the last received response is returned; if it was not possible to communicate with the server due to an error, then this is bubbled up.