diff options
author | Kierán Meinhardt <kmein@posteo.de> | 2024-10-12 15:11:50 +0200 |
---|---|---|
committer | Kierán Meinhardt <kmein@posteo.de> | 2024-10-12 15:16:03 +0200 |
commit | 29d9251b15d56f66d06551e158e992ace1856110 (patch) | |
tree | b7db48e67e03cdd099054085315e32e7301d9d41 /backend/lib/ACMS/API/REST.hs | |
parent | 47160b1fa5a9b351a999f5ca033dc165435af70e (diff) |
cli: factor out rest api location
Diffstat (limited to 'backend/lib/ACMS/API/REST.hs')
-rw-r--r-- | backend/lib/ACMS/API/REST.hs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/backend/lib/ACMS/API/REST.hs b/backend/lib/ACMS/API/REST.hs index 74d402c..64b47b7 100644 --- a/backend/lib/ACMS/API/REST.hs +++ b/backend/lib/ACMS/API/REST.hs @@ -5,7 +5,6 @@ module ACMS.API.REST where #ifndef ghcjs_HOST_OS import Network.HTTP.Simple #else -import Data.ByteString.Char8 qualified as B import Data.ByteString.Lazy.UTF8 qualified as LB import Data.Maybe import Data.String @@ -14,26 +13,35 @@ import Miso.String qualified as J #endif import Control.Monad.Catch (MonadThrow) import Data.Aeson qualified as A +import Data.ByteString.Char8 qualified as B import Data.ByteString.Lazy.Char8 qualified as LB import Data.Function ((&)) import Miso (JSM) import Miso.String (MisoString) +restRequest :: String -> Request +restRequest endpoint = + defaultRequest + & setRequestSecure False + & setRequestHost "localhost" + & setRequestPort 8081 + & setRequestPath ("/api/rest" <> B.pack endpoint) + schemaVersion :: (APIMonad m, A.FromJSON a) => m a schemaVersion = - "http://localhost:8081/api/rest/schemaVersion" + restRequest "/schemaVersion" & fetch >>= A.throwDecode listCollections :: (APIMonad m) => m [MisoString] listCollections = - "http://localhost:8081/api/rest/collection" + restRequest "/collection" & fetch >>= A.throwDecode createCollection :: (APIMonad m) => MisoString -> m () createCollection collection = - "http://localhost:8081/api/rest/collections" + restRequest "/collections" & setRequestMethod "POST" & setRequestBodyLBS (A.encode (A.toJSON collection)) & fetch |