diff options
author | Joris | 2019-10-20 21:31:57 +0200 |
---|---|---|
committer | Joris | 2019-10-20 21:31:57 +0200 |
commit | 602c52acfcfa494b07fec05c20b317b60ea8a6f3 (patch) | |
tree | 34fd9c44f82a83569822bc36eb2e0b04518e59f2 /client/src/Util | |
parent | 7aadcc97f9df0e2daccbe8a8726d8bc6c63d67f4 (diff) |
Load init data per page with AJAX
Diffstat (limited to 'client/src/Util')
-rw-r--r-- | client/src/Util/Ajax.hs | 21 |
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) |