aboutsummaryrefslogtreecommitdiff
path: root/client/src/Util/Ajax.hs
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/Util/Ajax.hs')
-rw-r--r--client/src/Util/Ajax.hs21
1 files changed, 15 insertions, 6 deletions
diff --git a/client/src/Util/Ajax.hs b/client/src/Util/Ajax.hs
index a4f6a74..9cd5105 100644
--- a/client/src/Util/Ajax.hs
+++ b/client/src/Util/Ajax.hs
@@ -1,6 +1,7 @@
module Util.Ajax
- ( postJson
- , putJson
+ ( get
+ , post
+ , put
, delete
) where
@@ -20,21 +21,29 @@ import Reflex.Dom (Dynamic, Event, IsXhrPayload,
XhrResponseHeaders (..))
import qualified Reflex.Dom as R
-postJson
+get
+ :: forall t m a. (MonadWidget t m, FromJSON a)
+ => Event t Text
+ -> m (Event t (Either Text a))
+get url =
+ fmap getJsonResult <$>
+ R.performRequestAsync (R.ffor url $ \u -> jsonRequest "GET" u (Aeson.String ""))
+
+post
:: forall t m a b. (MonadWidget t m, ToJSON a, FromJSON b)
=> Text
-> Event t a
-> m (Event t (Either Text b))
-postJson url input =
+post url input =
fmap getJsonResult <$>
R.performRequestAsync (jsonRequest "POST" url <$> input)
-putJson
+put
:: forall t m a b. (MonadWidget t m, ToJSON a, FromJSON b)
=> Text
-> Event t a
-> m (Event t (Either Text b))
-putJson url input =
+put url input =
fmap getJsonResult <$>
R.performRequestAsync (jsonRequest "PUT" url <$> input)