Problem loading data via HTTP in haste

27 views
Skip to first unread message

Herbert Lange

unread,
Nov 9, 2016, 10:47:53 AM11/9/16
to haste-compiler
Hi,
I started using haste for a small project recently. I want to load some data from an URL. 
I tried to use simpleHTTP from Network.HTTP but I get an error "Uncaught T2 ..."

A minimal example is

module Main where
import Network.HTTP
import Haste

main :: IO ()
main =
  do
    result <- simpleHTTP (getRequest "http://hackerbrau.se/foo.bar")
    body <- getResponseBody result
    alert body

When I try more or less the same with standard Haskell it works

module Main where
import Network.HTTP

main :: IO ()
main =
  do
    result <- simpleHTTP (getRequest "http://hackerbrau.se/foo.bar")
    body <- getResponseBody result
    putStrLn body

Is there a way to get this working or a more recommended way to load data?

Thanks for your help in advance

Herbert

Anton Ekblad

unread,
Nov 10, 2016, 12:44:36 PM11/10/16
to haste-compiler
Hi,
since the browser environment doesn't support all the bells and whistles of native networking, the HTTP package is not supported by Haste. If you want to make AJAX requests, please refer to Haste.Ajax or Haste.Concurrent. Due to a Haddock fail, the ajaxRequest exported by Haste.Concurrent doesn't seem to show up in the documentation at the moment, so please refer to its definition instead.

Note that the same origin policy will interfere with AJAX requests to domains other than the script's origin unless you either tell your browser to ignore it (not recommended), or use CSP to override it.

/Anton
Reply all
Reply to author
Forward
0 new messages