Module

Affjax

Note: this module is not intended to be used by end-users. Rather, use the environment-specific library instead:

You should use this module if you are writing a driver for a specific environment. See this module's source code for more details.

#Request

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

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

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

The type of records that represents a received HTTP response.

#Error

data Error

The possible errors that can occur when making an Affjax request.

Constructors

#printError

#URL

type URL = String

Type alias for URL strings to aid readability of types.

#AffjaxDriver

#request

request :: forall a. AffjaxDriver -> Request a -> Aff (Either Error (Response 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

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

Makes a GET request to the specified URL.

#post

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

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

#post_

post_ :: AffjaxDriver -> URL -> Maybe RequestBody -> Aff (Either Error Unit)

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

#put

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

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

#put_

put_ :: AffjaxDriver -> URL -> Maybe RequestBody -> Aff (Either Error Unit)

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

#delete

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

Makes a DELETE request to the specified URL.

#delete_

delete_ :: AffjaxDriver -> URL -> Aff (Either Error Unit)

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

#patch

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

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

#patch_

patch_ :: AffjaxDriver -> URL -> RequestBody -> Aff (Either Error Unit)

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

Modules