blob: 9f7cafa70a5950faaf8a0a6772d5da48ae1eca1f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
{-# LANGUAGE OverloadedStrings #-}
module ACMS.API.REST.Collection where
#ifndef ghcjs_HOST_OS
import Network.HTTP.Simple
#else
import ACMS.API.REST (setRequestMethod, setRequestBodyLBS, getResponseBody)
import Data.ByteString.Char8 qualified as B
import Data.Maybe
import JavaScript.Web.XMLHttpRequest
import Miso.String qualified as J
#endif
import ACMS.API.REST (APIMonad, fetch, restRequest)
import Data.Aeson qualified as A
import Data.Function ((&))
import Miso.String (MisoString)
import Text.Printf (printf)
list :: (APIMonad m) => MisoString -> m [A.Object]
list c =
restRequest (printf "/collection/%s" c)
& fetch
>>= A.throwDecode
read :: (APIMonad m) => MisoString -> MisoString -> m [A.Object]
read c i =
restRequest (printf "/collection/%s/%s" c i)
& fetch
>>= A.throwDecode
update :: (APIMonad m) => MisoString -> MisoString -> A.Object -> m ()
update c i o =
restRequest (printf "/collection/%s/%s" c i)
& setRequestMethod "PUT"
& setRequestBodyLBS (A.encode o)
& fetch
>>= A.throwDecode
create :: (APIMonad m) => MisoString -> A.Object -> m A.Object
create c o = do
restRequest (printf "/collection/%s" c)
& setRequestMethod "POST"
& setRequestBodyLBS (A.encode o)
& fetch
>>= A.throwDecode
delete :: (APIMonad m) => MisoString -> MisoString -> m [A.Object]
delete c i =
restRequest (printf "/collection/%s/%s" c i)
& setRequestMethod "DELETE"
& fetch
>>= A.throwDecode
schema :: (APIMonad m) => (A.FromJSON a) => MisoString -> m a
schema c =
restRequest (printf "/collection/%s/schema" c)
& fetch
>>= A.throwDecode
|