slamdata/purescript-affjax

Name: purescript-affjax

Owner: SlamData, Inc.

Description: An asynchronous AJAX library built using Aff.

Created: 2015-03-08 23:07:48.0

Updated: 2018-05-10 06:58:55.0

Pushed: 2018-05-14 10:47:51.0

Homepage: null

Size: 140

Language: PureScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

purescript-affjax

Latest release Build status

A library taking advantage of purescript-aff to enable pain-free asynchronous AJAX requests and response handling.

Getting Started

Installation
r install purescript-affjax

If you are intending to use the library in a Node.js setting rather than the browser, you will need an additional dependency from npm:

install xhr2
Introduction

You can construct requests with the affjax function:

le Main where

rt Prelude
rt Control.Monad.Eff.Console (log)
rt Control.Monad.Eff.Class (liftEff)
rt Control.Monad.Aff (launchAff)
rt Data.Either (Either(..))
rt Data.HTTP.Method (Method(..))
rt Network.HTTP.Affjax (affjax, defaultRequest)

 = launchAff $ do
s <- affjax $ defaultRequest { url = "/api", method = Left GET }
ftEff $ log $ "GET /api response: " <> res.response

(defaultRequest is a record value that has all the required fields pre-set for convenient overriding when making a request.)

Or use of a number of helpers for common cases:

rt Network.HTTP.Affjax (get, post)

 = launchAff $ do
s1 <- get "/api"
ftEff $ log $ "GET /api response: " <> res1.response

s2 <- post "/api" someData
ftEff $ log $ "POST /api response: " <> res2.response

See the module documentation for a full list of these helpers.

When sending data in a request the Requestable class enables automatic conversion into a format that is acceptable for an XHR request. Correspondingly there is a Respondable class for reading data that comes back from the server.

Module documentation

Module documentation is published on Pursuit.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.