Module

Affjax

Package
purescript-affjax
Repository
slamdata/purescript-affjax

#Request Source

type Request a = { content :: Maybe RequestBody, headers :: Array RequestHeader, method :: Either Method CustomMethod, password :: Maybe String, responseFormat :: ResponseFormat a, 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 :: Request Unit

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

As an example:

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

Would represents a POST request to the URL /api/user.

#Response Source

type Response a = { body :: a, headers :: Array ResponseHeader, status :: StatusCode, statusText :: String }

The type of records that represents a received HTTP response.

#URL Source

type URL = String

Type alias for URL strings to aid readability of types.

#request Source

request :: forall a. Request a -> Aff (Response (Either ResponseFormatError a))

Makes an HTTP request.

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

import Affjax.ResponseFormat (json)
...
request (defaultRequest { url = "/resource", method = Left GET, responseFormat = json})

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

get json "/resource"

#get Source

get :: forall a. ResponseFormat a -> URL -> Aff (Response (Either ResponseFormatError a))

Makes a GET request to the specified URL.

#post Source

post :: forall a. ResponseFormat a -> URL -> RequestBody -> Aff (Response (Either ResponseFormatError a))

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

#post_ Source

post_ :: URL -> RequestBody -> Aff (Response Unit)

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

#post' Source

post' :: forall a. ResponseFormat a -> URL -> Maybe RequestBody -> Aff (Response (Either ResponseFormatError a))

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

#post_' Source

post_' :: URL -> Maybe RequestBody -> Aff (Response Unit)

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

#put Source

put :: forall a. ResponseFormat a -> URL -> RequestBody -> Aff (Response (Either ResponseFormatError a))

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

#put_ Source

put_ :: URL -> RequestBody -> Aff (Response Unit)

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

#put' Source

put' :: forall a. ResponseFormat a -> URL -> Maybe RequestBody -> Aff (Response (Either ResponseFormatError a))

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

#put_' Source

put_' :: URL -> Maybe RequestBody -> Aff (Response Unit)

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

#delete Source

delete :: forall a. ResponseFormat a -> URL -> Aff (Response (Either ResponseFormatError a))

Makes a DELETE request to the specified URL.

#delete_ Source

delete_ :: URL -> Aff (Response Unit)

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

#patch Source

patch :: forall a. ResponseFormat a -> URL -> RequestBody -> Aff (Response (Either ResponseFormatError a))

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

#patch_ Source

patch_ :: URL -> RequestBody -> Aff (Response Unit)

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

#patch' Source

patch' :: forall a. ResponseFormat a -> URL -> Maybe RequestBody -> Aff (Response (Either ResponseFormatError a))

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

#patch_' Source

patch_' :: URL -> Maybe RequestBody -> Aff (Response 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 HTTP 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 b a. RetryPolicy -> (Request a -> Aff (Response b)) -> Request a -> Aff (Response b)

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.

Re-exports from Affjax.ResponseFormat

#ResponseFormatError Source

data ResponseFormatError

Used when an error occurs when attempting to decode into a particular response format. The error that occurred when decoding is included, along with the value that decoding was attempted on.

Constructors