diff options
Diffstat (limited to 'backend/lib/ACMS')
-rw-r--r-- | backend/lib/ACMS/API/REST.hs | 8 | ||||
-rw-r--r-- | backend/lib/ACMS/API/REST/Collection.hs | 8 |
2 files changed, 5 insertions, 11 deletions
diff --git a/backend/lib/ACMS/API/REST.hs b/backend/lib/ACMS/API/REST.hs index 64b47b7..ec72db9 100644 --- a/backend/lib/ACMS/API/REST.hs +++ b/backend/lib/ACMS/API/REST.hs @@ -13,19 +13,15 @@ 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 Data.String (IsString (fromString)) 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) + fromString ("http://localhost:8081/api/rest/" <> endpoint) schemaVersion :: (APIMonad m, A.FromJSON a) => m a schemaVersion = diff --git a/backend/lib/ACMS/API/REST/Collection.hs b/backend/lib/ACMS/API/REST/Collection.hs index 3ca8ffd..b3faf19 100644 --- a/backend/lib/ACMS/API/REST/Collection.hs +++ b/backend/lib/ACMS/API/REST/Collection.hs @@ -11,12 +11,10 @@ import Data.Maybe import JavaScript.Web.XMLHttpRequest import Miso.String qualified as J #endif -import Collection import ACMS.API.REST (APIMonad, fetch, restRequest) +import Collection import Data.Aeson qualified as A import Data.Function ((&)) -import Debug.Trace -import Miso.String (MisoString) import Text.Printf (printf) list :: (APIMonad m) => Collection -> m [A.Object] @@ -25,7 +23,7 @@ list c = & fetch >>= A.throwDecode -read :: (APIMonad m) => CollectionItem -> m [A.Object] +read :: (APIMonad m) => CollectionItem -> m (Maybe A.Object) read ci = restRequest (printf "/collection/%s/%s" ci.collection.name ci.itemFileName) & fetch @@ -47,7 +45,7 @@ create c o = do & fetch >>= A.throwDecode -delete :: (APIMonad m) => CollectionItem -> m [A.Object] +delete :: (APIMonad m) => CollectionItem -> m A.Object delete ci = restRequest (printf "/collection/%s/%s" ci.collection.name ci.itemFileName) & setRequestMethod "DELETE" |