Usage with Affjax

There is an issue that discusses how usage with Affjax goes here:


In short, you can use the string response format for the request:

import Prelude
import Affjax (get, printError)
import Affjax.ResponseFormat (string)
import Data.Either (Either(..))
import Effect (Effect)
import Effect.Aff (launchAff_)
import Effect.Class.Console (log)
import Simple.JSON (readJSON)

type MyRecordAlias
  = { userId :: Int }

main :: Effect Unit
main =
    $ do
        res <- get string ""
        case res of
          Left err -> do
            log $ "GET /api response failed to decode: " <> printError err
          Right response -> do
            case readJSON response.body of
              Right (r :: MyRecordAlias) -> do
                log $ "userID is: " <> show r.userId
              Left e -> do
                log $ "Can't parse JSON. " <> show e

With Simple-Ajax

You can use Dario’s library for making requests with Affjax and handling errors with Variant here: