dariooddenino/purescript-simple-ajax

Readme is outdated

Closed this issue · 3 comments

Hi there!

I'm a purescript newbie and after trying quite some time to make the readme example work, I just give up.

Apparently this example:

payload :: { foo :: Int, bar :: String }
payload = { foo: 1, bar: "hello" }

type Baz = { baz :: Boolean }

main = launchAff_ $ do
  res <- post url (Just payload)
  case res of
    Left err -> do
      let error = 
        default "Generic error" 
        # on _notAuthorized $ const "Not authorized" 
        $ err
      log error
    Right (res :: Baz) ->
      logShow res

is just broken. I get indent errors in the let error = part, which I don't really know if is something with purescript itself or bad formatting.

Then, _notAuthorized was being renamed to _unAuthorized, so that also doesn't work.

And after that, I probably got wrong the Variant version. I get this error:

Error found:
in module Main
at src/Main.purs:65:19 - 65:92 (line 65, column 19 - line 65, column 92)

Could not match type

String

with type

Variant t0 -> String


while checking that type String
is at least as general as type Variant t0 -> String
while checking that expression (apply (const "Not authorized")) err
has type Variant t0 -> String
in value declaration main

where t0 is an unknown type

Could you please update the example with something that works? It would really help me and other beginners that just want to do a simple get to some webservice.

Thanks for the lib :)

Hi! Thank you for taking the time to write this down, and sorry for the issues coming from the outdated example.

I have updated it and it should work fine. Let me know if there's anything else! :)

It perfectly works 👍

I still have doubts why purescript doesn't like tabs of 2 spaces, the code I previously wrote looks well indented to me. I took an unnecessary amount of time trying to debug that, but that's on me ofc

I'll try to use this at work! I'll post issues if I find some :)

Your ide/editor should give you an error and indent correctly in this cases, maybe there's something wrong with your setup?