blob: 6cd2982e6f1f8cc17c23c6a9f054f5336e2ecd94 (
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
|
{-# LANGUAGE OverloadedStrings #-}
module ACMS.API.REST where
import ACMS.API.Fetch
import Data.Aeson qualified as A
import Data.Function ((&))
import Data.String (IsString (fromString))
import Miso.String (MisoString)
restRequest :: String -> Request
restRequest endpoint =
fromString ("http://localhost:8081/api/rest" <> endpoint)
schemaVersion :: (APIMonad m, A.FromJSON a) => m a
schemaVersion =
restRequest "/schemaVersion"
& fetch
>>= A.throwDecode
listCollections :: (APIMonad m) => m [MisoString]
listCollections =
restRequest "/collection"
& fetch
>>= A.throwDecode
createCollection :: (APIMonad m) => MisoString -> m ()
createCollection collection =
restRequest "/collections"
& setRequestMethod "POST"
& setRequestBodyLBS (A.encode (A.toJSON collection))
& fetch
>>= A.throwDecode
|