{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Miso.Fetch
(
getJSON
, postJSON
, postJSON'
, putJSON
, getText
, postText
, putText
, getBlob
, postBlob
, putBlob
, getFormData
, postFormData
, putFormData
, getUint8Array
, postUint8Array
, putUint8Array
, postImage
, putImage
, getArrayBuffer
, postArrayBuffer
, putArrayBuffer
, accept
, contentType
, applicationJSON
, textPlain
, formData
, Body
, Response (..)
, CONTENT_TYPE (..)
, getJSON_
, postJSON_
, postJSON'_
, putJSON_
, getText_
, postText_
, putText_
, getBlob_
, postBlob_
, putBlob_
, getFormData_
, postFormData_
, putFormData_
, getUint8Array_
, postUint8Array_
, putUint8Array_
, postImage_
, putImage_
, getArrayBuffer_
, postArrayBuffer_
, putArrayBuffer_
, fetch
) where
import Control.Concurrent (MVar, newEmptyMVar, putMVar, takeMVar)
import Miso.JSON
import qualified Data.Map.Strict as M
import Miso.DSL (toJSVal, FromJSVal(..), JSVal)
import qualified Miso.FFI.Internal as FFI
import Miso.Effect (Effect, withSink)
import Miso.String (MisoString, ms)
import Miso.Util ((=:))
import Miso.FFI.Internal (Response(..), Blob, FormData, ArrayBuffer, Uint8Array, Image, fetch, CONTENT_TYPE(..))
getJSON
:: (FromJSON body, FromJSVal error)
=> MisoString
-> [(MisoString, MisoString)]
-> (Response body -> action)
-> (Response error -> action)
-> Effect context props model action
getJSON :: forall body error action context props model.
(FromJSON body, FromJSVal error) =>
MisoString
-> [(MisoString, MisoString)]
-> (Response body -> action)
-> (Response error -> action)
-> Effect context props model action
getJSON MisoString
url [(MisoString, MisoString)]
headers_ Response body -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink ->
MisoString
-> MisoString
-> Maybe JSVal
-> [(MisoString, MisoString)]
-> (Response JSVal -> IO ())
-> (Response error -> IO ())
-> CONTENT_TYPE
-> IO ()
forall success error.
(FromJSVal success, FromJSVal error) =>
MisoString
-> MisoString
-> Maybe JSVal
-> [(MisoString, MisoString)]
-> (Response success -> IO ())
-> (Response error -> IO ())
-> CONTENT_TYPE
-> IO ()
FFI.fetch MisoString
url MisoString
"GET" Maybe JSVal
forall a. Maybe a
Nothing [(MisoString, MisoString)]
jsonHeaders
(Sink action -> Response JSVal -> IO ()
forall {b}. (action -> IO b) -> Response JSVal -> IO b
handleJSON Sink action
sink)
(Sink action
sink Sink action
-> (Response error -> action) -> Response error -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Response error -> action
errorful)
CONTENT_TYPE
JSON
where
jsonHeaders :: [(MisoString, MisoString)]
jsonHeaders = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
accept MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
applicationJSON]
handleJSON :: (action -> IO b) -> Response JSVal -> IO b
handleJSON action -> IO b
sink resp :: Response JSVal
resp@Response {Maybe Int
Maybe MisoString
Map MisoString MisoString
JSVal
status :: Maybe Int
headers :: Map MisoString MisoString
errorMessage :: Maybe MisoString
body :: JSVal
body :: forall body. Response body -> body
errorMessage :: forall body. Response body -> Maybe MisoString
headers :: forall body. Response body -> Map MisoString MisoString
status :: forall body. Response body -> Maybe Int
..} =
(Value -> Result body) -> Maybe Value -> Maybe (Result body)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Value -> Result body
forall a. FromJSON a => Value -> Result a
fromJSON (Maybe Value -> Maybe (Result body))
-> IO (Maybe Value) -> IO (Maybe (Result body))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSVal -> IO (Maybe Value)
forall a. FromJSVal a => JSVal -> IO (Maybe a)
fromJSVal JSVal
body IO (Maybe (Result body)) -> (Maybe (Result body) -> IO b) -> IO b
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Maybe (Result body)
Nothing -> do
err <- JSVal -> IO error
forall a. FromJSVal a => JSVal -> IO a
fromJSValUnchecked JSVal
body
sink $ errorful $ Response
{ body = err
, errorMessage = Just "Not a valid JSON object"
, ..
}
Just (Success body
result) ->
action -> IO b
sink (action -> IO b) -> action -> IO b
forall a b. (a -> b) -> a -> b
$ Response body -> action
successful Response JSVal
resp { body = result }
Just (Error MisoString
msg) -> do
err <- JSVal -> IO error
forall a. FromJSVal a => JSVal -> IO a
fromJSValUnchecked JSVal
body
sink $ errorful $ Response
{ body = err
, errorMessage = Just (ms msg)
, ..
}
postJSON
:: (FromJSVal error, ToJSON body)
=> MisoString
-> body
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
postJSON :: forall error body action context props model.
(FromJSVal error, ToJSON body) =>
MisoString
-> body
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
postJSON MisoString
url body
body_ [(MisoString, MisoString)]
headers_ Response () -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink -> do
bodyVal <- MisoString -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal (body -> MisoString
forall a. ToJSON a => a -> MisoString
encode body
body_)
FFI.fetch url "POST" (Just bodyVal) jsonHeaders_
(sink . successful)
(sink . errorful)
NONE
where
jsonHeaders_ :: [(MisoString, MisoString)]
jsonHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
applicationJSON]
postJSON'
:: (FromJSVal error, ToJSON body, FromJSON return)
=> MisoString
-> body
-> [(MisoString, MisoString)]
-> (Response return -> action)
-> (Response error -> action)
-> Effect context props model action
postJSON' :: forall error body return action context props model.
(FromJSVal error, ToJSON body, FromJSON return) =>
MisoString
-> body
-> [(MisoString, MisoString)]
-> (Response return -> action)
-> (Response error -> action)
-> Effect context props model action
postJSON' MisoString
url body
body_ [(MisoString, MisoString)]
headers_ Response return -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink -> do
bodyVal <- MisoString -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal (body -> MisoString
forall a. ToJSON a => a -> MisoString
encode body
body_)
FFI.fetch url "POST" (Just bodyVal) jsonHeaders_
(handleJSON sink)
(sink . errorful)
JSON
where
jsonHeaders_ :: [(MisoString, MisoString)]
jsonHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
applicationJSON, MisoString
accept MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
applicationJSON]
handleJSON :: (action -> IO b) -> Response JSVal -> IO b
handleJSON action -> IO b
sink resp :: Response JSVal
resp@Response {Maybe Int
Maybe MisoString
Map MisoString MisoString
JSVal
body :: forall body. Response body -> body
errorMessage :: forall body. Response body -> Maybe MisoString
headers :: forall body. Response body -> Map MisoString MisoString
status :: forall body. Response body -> Maybe Int
status :: Maybe Int
headers :: Map MisoString MisoString
errorMessage :: Maybe MisoString
body :: JSVal
..} =
(Value -> Result return) -> Maybe Value -> Maybe (Result return)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Value -> Result return
forall a. FromJSON a => Value -> Result a
fromJSON (Maybe Value -> Maybe (Result return))
-> IO (Maybe Value) -> IO (Maybe (Result return))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSVal -> IO (Maybe Value)
forall a. FromJSVal a => JSVal -> IO (Maybe a)
fromJSVal JSVal
body IO (Maybe (Result return))
-> (Maybe (Result return) -> IO b) -> IO b
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Maybe (Result return)
Nothing -> do
err <- JSVal -> IO error
forall a. FromJSVal a => JSVal -> IO a
fromJSValUnchecked JSVal
body
sink $ errorful $ Response
{ body = err
, errorMessage = Just "Not a valid JSON object"
, ..
}
Just (Success return
result) ->
action -> IO b
sink (action -> IO b) -> action -> IO b
forall a b. (a -> b) -> a -> b
$ Response return -> action
successful Response JSVal
resp { body = result }
Just (Error MisoString
msg) -> do
err <- JSVal -> IO error
forall a. FromJSVal a => JSVal -> IO a
fromJSValUnchecked JSVal
body
sink $ errorful $ Response
{ body = err
, errorMessage = Just (ms msg)
, ..
}
putJSON
:: (FromJSVal error, ToJSON body)
=> MisoString
-> body
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
putJSON :: forall error body action context props model.
(FromJSVal error, ToJSON body) =>
MisoString
-> body
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
putJSON MisoString
url body
body_ [(MisoString, MisoString)]
headers_ Response () -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink -> do
bodyVal <- MisoString -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal (body -> MisoString
forall a. ToJSON a => a -> MisoString
encode body
body_)
FFI.fetch url "PUT" (Just bodyVal) jsonHeaders_
(sink . successful)
(sink . errorful)
NONE
where
jsonHeaders_ :: [(MisoString, MisoString)]
jsonHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
applicationJSON]
getText
:: FromJSVal error
=> MisoString
-> [(MisoString, MisoString)]
-> (Response MisoString -> action)
-> (Response error -> action)
-> Effect context props model action
getText :: forall error action context props model.
FromJSVal error =>
MisoString
-> [(MisoString, MisoString)]
-> (Response MisoString -> action)
-> (Response error -> action)
-> Effect context props model action
getText MisoString
url [(MisoString, MisoString)]
headers_ Response MisoString -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink ->
MisoString
-> MisoString
-> Maybe JSVal
-> [(MisoString, MisoString)]
-> (Response MisoString -> IO ())
-> (Response error -> IO ())
-> CONTENT_TYPE
-> IO ()
forall success error.
(FromJSVal success, FromJSVal error) =>
MisoString
-> MisoString
-> Maybe JSVal
-> [(MisoString, MisoString)]
-> (Response success -> IO ())
-> (Response error -> IO ())
-> CONTENT_TYPE
-> IO ()
FFI.fetch MisoString
url MisoString
"GET" Maybe JSVal
forall a. Maybe a
Nothing [(MisoString, MisoString)]
textHeaders_
(Sink action
sink Sink action
-> (Response MisoString -> action) -> Response MisoString -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Response MisoString -> action
successful)
(Sink action
sink Sink action
-> (Response error -> action) -> Response error -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Response error -> action
errorful)
CONTENT_TYPE
TEXT
where
textHeaders_ :: [(MisoString, MisoString)]
textHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
accept MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
textPlain]
postText
:: FromJSVal error
=> MisoString
-> MisoString
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
postText :: forall error action context props model.
FromJSVal error =>
MisoString
-> MisoString
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
postText MisoString
url MisoString
body_ [(MisoString, MisoString)]
headers_ Response () -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink -> do
bodyVal <- MisoString -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal (MisoString -> MisoString
forall a. ToJSON a => a -> MisoString
encode MisoString
body_)
FFI.fetch url "POST" (Just bodyVal) textHeaders_
(sink . successful)
(sink . errorful)
NONE
where
textHeaders_ :: [(MisoString, MisoString)]
textHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
textPlain]
putText
:: FromJSVal error
=> MisoString
-> MisoString
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
putText :: forall error action context props model.
FromJSVal error =>
MisoString
-> MisoString
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
putText MisoString
url MisoString
imageBody [(MisoString, MisoString)]
headers_ Response () -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink -> do
body_ <- MisoString -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal MisoString
imageBody
FFI.fetch url "PUT" (Just body_) textHeaders_
(sink . successful)
(sink . errorful)
NONE
where
textHeaders_ :: [(MisoString, MisoString)]
textHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
textPlain]
getBlob
:: FromJSVal error
=> MisoString
-> [(MisoString, MisoString)]
-> (Response Blob -> action)
-> (Response error -> action)
-> Effect context props model action
getBlob :: forall error action context props model.
FromJSVal error =>
MisoString
-> [(MisoString, MisoString)]
-> (Response Blob -> action)
-> (Response error -> action)
-> Effect context props model action
getBlob MisoString
url [(MisoString, MisoString)]
headers_ Response Blob -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink ->
MisoString
-> MisoString
-> Maybe JSVal
-> [(MisoString, MisoString)]
-> (Response Blob -> IO ())
-> (Response error -> IO ())
-> CONTENT_TYPE
-> IO ()
forall success error.
(FromJSVal success, FromJSVal error) =>
MisoString
-> MisoString
-> Maybe JSVal
-> [(MisoString, MisoString)]
-> (Response success -> IO ())
-> (Response error -> IO ())
-> CONTENT_TYPE
-> IO ()
FFI.fetch MisoString
url MisoString
"GET" Maybe JSVal
forall a. Maybe a
Nothing [(MisoString, MisoString)]
blobHeaders_
(Sink action
sink Sink action -> (Response Blob -> action) -> Response Blob -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Response Blob -> action
successful)
(Sink action
sink Sink action
-> (Response error -> action) -> Response error -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Response error -> action
errorful)
CONTENT_TYPE
BLOB
where
blobHeaders_ :: [(MisoString, MisoString)]
blobHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
accept MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
octetStream]
postBlob
:: FromJSVal error
=> MisoString
-> Blob
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
postBlob :: forall error action context props model.
FromJSVal error =>
MisoString
-> Blob
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
postBlob MisoString
url Blob
body_ [(MisoString, MisoString)]
headers_ Response () -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink -> do
bodyVal <- Blob -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal Blob
body_
FFI.fetch url "POST" (Just bodyVal) blobHeaders_
(sink . successful)
(sink . errorful)
NONE
where
blobHeaders_ :: [(MisoString, MisoString)]
blobHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
octetStream]
putBlob
:: FromJSVal error
=> MisoString
-> Blob
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
putBlob :: forall error action context props model.
FromJSVal error =>
MisoString
-> Blob
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
putBlob MisoString
url Blob
imageBody [(MisoString, MisoString)]
headers_ Response () -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink -> do
body_ <- Blob -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal Blob
imageBody
FFI.fetch url "PUT" (Just body_) blobHeaders_
(sink . successful)
(sink . errorful)
NONE
where
blobHeaders_ :: [(MisoString, MisoString)]
blobHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
octetStream]
getFormData
:: FromJSVal error
=> MisoString
-> [(MisoString, MisoString)]
-> (Response FormData -> action)
-> (Response error -> action)
-> Effect context props model action
getFormData :: forall error action context props model.
FromJSVal error =>
MisoString
-> [(MisoString, MisoString)]
-> (Response FormData -> action)
-> (Response error -> action)
-> Effect context props model action
getFormData MisoString
url [(MisoString, MisoString)]
headers_ Response FormData -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink ->
MisoString
-> MisoString
-> Maybe JSVal
-> [(MisoString, MisoString)]
-> (Response FormData -> IO ())
-> (Response error -> IO ())
-> CONTENT_TYPE
-> IO ()
forall success error.
(FromJSVal success, FromJSVal error) =>
MisoString
-> MisoString
-> Maybe JSVal
-> [(MisoString, MisoString)]
-> (Response success -> IO ())
-> (Response error -> IO ())
-> CONTENT_TYPE
-> IO ()
FFI.fetch MisoString
url MisoString
"GET" Maybe JSVal
forall a. Maybe a
Nothing [(MisoString, MisoString)]
formDataHeaders_
(Sink action
sink Sink action
-> (Response FormData -> action) -> Response FormData -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Response FormData -> action
successful)
(Sink action
sink Sink action
-> (Response error -> action) -> Response error -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Response error -> action
errorful)
CONTENT_TYPE
FORM_DATA
where
formDataHeaders_ :: [(MisoString, MisoString)]
formDataHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
accept MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
formData]
postFormData
:: FromJSVal error
=> MisoString
-> FormData
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
postFormData :: forall error action context props model.
FromJSVal error =>
MisoString
-> FormData
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
postFormData MisoString
url FormData
body_ [(MisoString, MisoString)]
headers_ Response () -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink -> do
bodyVal <- FormData -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal FormData
body_
FFI.fetch url "POST" (Just bodyVal) formDataHeaders_
(sink . successful)
(sink . errorful)
NONE
where
formDataHeaders_ :: [(MisoString, MisoString)]
formDataHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
formData]
putFormData
:: FromJSVal error
=> MisoString
-> FormData
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
putFormData :: forall error action context props model.
FromJSVal error =>
MisoString
-> FormData
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
putFormData MisoString
url FormData
imageBody [(MisoString, MisoString)]
headers_ Response () -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink -> do
body_ <- FormData -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal FormData
imageBody
FFI.fetch url "PUT" (Just body_) formDataHeaders_
(sink . successful)
(sink . errorful)
NONE
where
formDataHeaders_ :: [(MisoString, MisoString)]
formDataHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
formData]
getArrayBuffer
:: FromJSVal error
=> MisoString
-> [(MisoString, MisoString)]
-> (Response ArrayBuffer -> action)
-> (Response error -> action)
-> Effect context props model action
getArrayBuffer :: forall error action context props model.
FromJSVal error =>
MisoString
-> [(MisoString, MisoString)]
-> (Response ArrayBuffer -> action)
-> (Response error -> action)
-> Effect context props model action
getArrayBuffer MisoString
url [(MisoString, MisoString)]
headers_ Response ArrayBuffer -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink ->
MisoString
-> MisoString
-> Maybe JSVal
-> [(MisoString, MisoString)]
-> (Response ArrayBuffer -> IO ())
-> (Response error -> IO ())
-> CONTENT_TYPE
-> IO ()
forall success error.
(FromJSVal success, FromJSVal error) =>
MisoString
-> MisoString
-> Maybe JSVal
-> [(MisoString, MisoString)]
-> (Response success -> IO ())
-> (Response error -> IO ())
-> CONTENT_TYPE
-> IO ()
FFI.fetch MisoString
url MisoString
"GET" Maybe JSVal
forall a. Maybe a
Nothing [(MisoString, MisoString)]
arrayBufferHeaders_
(Sink action
sink Sink action
-> (Response ArrayBuffer -> action)
-> Response ArrayBuffer
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Response ArrayBuffer -> action
successful)
(Sink action
sink Sink action
-> (Response error -> action) -> Response error -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Response error -> action
errorful)
CONTENT_TYPE
ARRAY_BUFFER
where
arrayBufferHeaders_ :: [(MisoString, MisoString)]
arrayBufferHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
accept MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
octetStream]
postArrayBuffer
:: FromJSVal error
=> MisoString
-> ArrayBuffer
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
postArrayBuffer :: forall error action context props model.
FromJSVal error =>
MisoString
-> ArrayBuffer
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
postArrayBuffer MisoString
url ArrayBuffer
body_ [(MisoString, MisoString)]
headers_ Response () -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink -> do
bodyVal <- ArrayBuffer -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal ArrayBuffer
body_
FFI.fetch url "POST" (Just bodyVal) arrayBufferHeaders_
(sink . successful)
(sink . errorful)
NONE
where
arrayBufferHeaders_ :: [(MisoString, MisoString)]
arrayBufferHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
octetStream]
putArrayBuffer
:: FromJSVal error
=> MisoString
-> ArrayBuffer
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
putArrayBuffer :: forall error action context props model.
FromJSVal error =>
MisoString
-> ArrayBuffer
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
putArrayBuffer MisoString
url ArrayBuffer
arrayBuffer_ [(MisoString, MisoString)]
headers_ Response () -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink -> do
body_ <- ArrayBuffer -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal ArrayBuffer
arrayBuffer_
FFI.fetch url "PUT" (Just body_) arrayBufferHeaders_
(sink . successful)
(sink . errorful)
NONE
where
arrayBufferHeaders_ :: [(MisoString, MisoString)]
arrayBufferHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
octetStream]
getUint8Array
:: FromJSVal error
=> MisoString
-> [(MisoString, MisoString)]
-> (Response Uint8Array -> action)
-> (Response error -> action)
-> Effect context props model action
getUint8Array :: forall error action context props model.
FromJSVal error =>
MisoString
-> [(MisoString, MisoString)]
-> (Response Uint8Array -> action)
-> (Response error -> action)
-> Effect context props model action
getUint8Array MisoString
url [(MisoString, MisoString)]
headers_ Response Uint8Array -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink ->
MisoString
-> MisoString
-> Maybe JSVal
-> [(MisoString, MisoString)]
-> (Response Uint8Array -> IO ())
-> (Response error -> IO ())
-> CONTENT_TYPE
-> IO ()
forall success error.
(FromJSVal success, FromJSVal error) =>
MisoString
-> MisoString
-> Maybe JSVal
-> [(MisoString, MisoString)]
-> (Response success -> IO ())
-> (Response error -> IO ())
-> CONTENT_TYPE
-> IO ()
FFI.fetch MisoString
url MisoString
"GET" Maybe JSVal
forall a. Maybe a
Nothing [(MisoString, MisoString)]
uint8ArrayHeaders_
(Sink action
sink Sink action
-> (Response Uint8Array -> action) -> Response Uint8Array -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Response Uint8Array -> action
successful)
(Sink action
sink Sink action
-> (Response error -> action) -> Response error -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Response error -> action
errorful)
CONTENT_TYPE
BYTES
where
uint8ArrayHeaders_ :: [(MisoString, MisoString)]
uint8ArrayHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
accept MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
octetStream]
postUint8Array
:: FromJSVal error
=> MisoString
-> Uint8Array
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
postUint8Array :: forall error action context props model.
FromJSVal error =>
MisoString
-> Uint8Array
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
postUint8Array MisoString
url Uint8Array
body_ [(MisoString, MisoString)]
headers_ Response () -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink -> do
bodyVal <- Uint8Array -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal Uint8Array
body_
FFI.fetch url "POST" (Just bodyVal) uint8ArrayHeaders_
(sink . successful)
(sink . errorful)
NONE
where
uint8ArrayHeaders_ :: [(MisoString, MisoString)]
uint8ArrayHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
octetStream]
putUint8Array
:: FromJSVal error
=> MisoString
-> Uint8Array
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
putUint8Array :: forall error action context props model.
FromJSVal error =>
MisoString
-> Uint8Array
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
putUint8Array MisoString
url Uint8Array
uint8Array_ [(MisoString, MisoString)]
headers_ Response () -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink -> do
body_ <- Uint8Array -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal Uint8Array
uint8Array_
FFI.fetch url "PUT" (Just body_) uint8ArrayHeaders_
(sink . successful)
(sink . errorful)
NONE
where
uint8ArrayHeaders_ :: [(MisoString, MisoString)]
uint8ArrayHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
octetStream]
postImage
:: FromJSVal error
=> MisoString
-> Image
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
postImage :: forall error action context props model.
FromJSVal error =>
MisoString
-> Image
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
postImage MisoString
url Image
body_ [(MisoString, MisoString)]
headers_ Response () -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink -> do
bodyVal <- Image -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal Image
body_
FFI.fetch url "POST" (Just bodyVal) headers_
(sink . successful)
(sink . errorful)
NONE
putImage
:: FromJSVal error
=> MisoString
-> Image
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
putImage :: forall error action context props model.
FromJSVal error =>
MisoString
-> Image
-> [(MisoString, MisoString)]
-> (Response () -> action)
-> (Response error -> action)
-> Effect context props model action
putImage MisoString
url Image
imageBody [(MisoString, MisoString)]
headers_ Response () -> action
successful Response error -> action
errorful =
(Sink action -> IO ()) -> Effect context props model action
forall action context props model.
(Sink action -> IO ()) -> Effect context props model action
withSink ((Sink action -> IO ()) -> Effect context props model action)
-> (Sink action -> IO ()) -> Effect context props model action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink -> do
body_ <- Image -> IO JSVal
forall a. ToJSVal a => a -> IO JSVal
toJSVal Image
imageBody
FFI.fetch url "PUT" (Just body_) headers_
(sink . successful)
(sink . errorful)
NONE
type Body = JSVal
accept :: MisoString
accept :: MisoString
accept = MisoString
"Accept"
contentType :: MisoString
contentType :: MisoString
contentType = MisoString
"Content-Type"
applicationJSON :: MisoString
applicationJSON :: MisoString
applicationJSON = MisoString
"application/json"
textPlain :: MisoString
textPlain :: MisoString
textPlain = MisoString
"text/plain"
octetStream :: MisoString
octetStream :: MisoString
octetStream = MisoString
"application/octet-stream"
formData :: MisoString
formData :: MisoString
formData = MisoString
"multipart/form-data"
biasHeaders :: Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
[(k, a)]
userDefined [(k, a)]
contentSpecific
= Map k a -> [(k, a)]
forall k a. Map k a -> [(k, a)]
M.toList
(Map k a -> [(k, a)]) -> Map k a -> [(k, a)]
forall a b. (a -> b) -> a -> b
$ [(k, a)] -> Map k a
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(k, a)]
userDefined Map k a -> Map k a -> Map k a
forall a. Semigroup a => a -> a -> a
<> [(k, a)] -> Map k a
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(k, a)]
contentSpecific
getJSON_
:: (FromJSON body, FromJSVal error)
=> MisoString
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response body))
getJSON_ :: forall body error.
(FromJSON body, FromJSVal error) =>
MisoString
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response body))
getJSON_ MisoString
url [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response body)))
forall a. IO (MVar a)
forall {error} {body}.
IO (MVar (Either (Response error) (Response body)))
newEmptyMVar :: IO (MVar (Either (Response error) (Response body)))
FFI.fetch url "GET" Nothing jsonHeaders
(handleJSON mvar)
(putMVar mvar . Left)
JSON
takeMVar mvar
where
jsonHeaders :: [(MisoString, MisoString)]
jsonHeaders = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
accept MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
applicationJSON]
handleJSON :: MVar (Either (Response body) (Response body))
-> Response JSVal -> IO ()
handleJSON MVar (Either (Response body) (Response body))
mvar resp :: Response JSVal
resp@Response {Maybe Int
Maybe MisoString
Map MisoString MisoString
JSVal
body :: forall body. Response body -> body
errorMessage :: forall body. Response body -> Maybe MisoString
headers :: forall body. Response body -> Map MisoString MisoString
status :: forall body. Response body -> Maybe Int
status :: Maybe Int
headers :: Map MisoString MisoString
errorMessage :: Maybe MisoString
body :: JSVal
..} =
(Value -> Result body) -> Maybe Value -> Maybe (Result body)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Value -> Result body
forall a. FromJSON a => Value -> Result a
fromJSON (Maybe Value -> Maybe (Result body))
-> IO (Maybe Value) -> IO (Maybe (Result body))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSVal -> IO (Maybe Value)
forall a. FromJSVal a => JSVal -> IO (Maybe a)
fromJSVal JSVal
body IO (Maybe (Result body)) -> (Maybe (Result body) -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Maybe (Result body)
Nothing -> do
err <- JSVal -> IO body
forall a. FromJSVal a => JSVal -> IO a
fromJSValUnchecked JSVal
body
putMVar mvar $ Left $ Response
{ body = err
, errorMessage = Just "Not a valid JSON object"
, ..
}
Just (Success body
result) ->
MVar (Either (Response body) (Response body))
-> Either (Response body) (Response body) -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar (Either (Response body) (Response body))
mvar (Either (Response body) (Response body) -> IO ())
-> Either (Response body) (Response body) -> IO ()
forall a b. (a -> b) -> a -> b
$ Response body -> Either (Response body) (Response body)
forall a b. b -> Either a b
Right Response JSVal
resp { body = result }
Just (Error MisoString
msg) -> do
err <- JSVal -> IO body
forall a. FromJSVal a => JSVal -> IO a
fromJSValUnchecked JSVal
body
putMVar mvar $ Left $ Response
{ body = err
, errorMessage = Just (ms msg)
, ..
}
{-# INLINE getJSON_ #-}
postJSON_
:: (FromJSVal error, ToJSON body)
=> MisoString
-> body
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
postJSON_ :: forall error body.
(FromJSVal error, ToJSON body) =>
MisoString
-> body
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
postJSON_ MisoString
url body
body_ [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response ())))
forall a. IO (MVar a)
forall {error}. IO (MVar (Either (Response error) (Response ())))
newEmptyMVar :: IO (MVar (Either (Response error) (Response ())))
bodyVal <- toJSVal (encode body_)
FFI.fetch url "POST" (Just bodyVal) jsonHeaders_
(putMVar mvar . Right)
(putMVar mvar . Left)
NONE
takeMVar mvar
where
jsonHeaders_ :: [(MisoString, MisoString)]
jsonHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
applicationJSON]
{-# INLINE postJSON_ #-}
postJSON'_
:: (FromJSVal error, ToJSON body, FromJSON return)
=> MisoString
-> body
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response return))
postJSON'_ :: forall error body return.
(FromJSVal error, ToJSON body, FromJSON return) =>
MisoString
-> body
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response return))
postJSON'_ MisoString
url body
body_ [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response return)))
forall a. IO (MVar a)
forall {error} {body}.
IO (MVar (Either (Response error) (Response body)))
newEmptyMVar :: IO (MVar (Either (Response error) (Response return)))
bodyVal <- toJSVal (encode body_)
FFI.fetch url "POST" (Just bodyVal) jsonHeaders_
(handleJSON mvar)
(putMVar mvar . Left)
JSON
takeMVar mvar
where
jsonHeaders_ :: [(MisoString, MisoString)]
jsonHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
applicationJSON, MisoString
accept MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
applicationJSON]
handleJSON :: MVar (Either (Response body) (Response body))
-> Response JSVal -> IO ()
handleJSON MVar (Either (Response body) (Response body))
mvar resp :: Response JSVal
resp@Response {Maybe Int
Maybe MisoString
Map MisoString MisoString
JSVal
body :: forall body. Response body -> body
errorMessage :: forall body. Response body -> Maybe MisoString
headers :: forall body. Response body -> Map MisoString MisoString
status :: forall body. Response body -> Maybe Int
status :: Maybe Int
headers :: Map MisoString MisoString
errorMessage :: Maybe MisoString
body :: JSVal
..} =
(Value -> Result body) -> Maybe Value -> Maybe (Result body)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Value -> Result body
forall a. FromJSON a => Value -> Result a
fromJSON (Maybe Value -> Maybe (Result body))
-> IO (Maybe Value) -> IO (Maybe (Result body))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSVal -> IO (Maybe Value)
forall a. FromJSVal a => JSVal -> IO (Maybe a)
fromJSVal JSVal
body IO (Maybe (Result body)) -> (Maybe (Result body) -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Maybe (Result body)
Nothing -> do
err <- JSVal -> IO body
forall a. FromJSVal a => JSVal -> IO a
fromJSValUnchecked JSVal
body
putMVar mvar $ Left $ Response
{ body = err
, errorMessage = Just "Not a valid JSON object"
, ..
}
Just (Success body
result) ->
MVar (Either (Response body) (Response body))
-> Either (Response body) (Response body) -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar (Either (Response body) (Response body))
mvar (Either (Response body) (Response body) -> IO ())
-> Either (Response body) (Response body) -> IO ()
forall a b. (a -> b) -> a -> b
$ Response body -> Either (Response body) (Response body)
forall a b. b -> Either a b
Right Response JSVal
resp { body = result }
Just (Error MisoString
msg) -> do
err <- JSVal -> IO body
forall a. FromJSVal a => JSVal -> IO a
fromJSValUnchecked JSVal
body
putMVar mvar $ Left $ Response
{ body = err
, errorMessage = Just (ms msg)
, ..
}
{-# INLINE postJSON'_ #-}
putJSON_
:: (FromJSVal error, ToJSON body)
=> MisoString
-> body
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
putJSON_ :: forall error body.
(FromJSVal error, ToJSON body) =>
MisoString
-> body
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
putJSON_ MisoString
url body
body_ [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response ())))
forall a. IO (MVar a)
forall {error}. IO (MVar (Either (Response error) (Response ())))
newEmptyMVar :: IO (MVar (Either (Response error) (Response ())))
bodyVal <- toJSVal (encode body_)
FFI.fetch url "PUT" (Just bodyVal) jsonHeaders_
(putMVar mvar . Right)
(putMVar mvar . Left)
NONE
takeMVar mvar
where
jsonHeaders_ :: [(MisoString, MisoString)]
jsonHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
applicationJSON]
{-# INLINE putJSON_ #-}
getText_
:: FromJSVal error
=> MisoString
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response MisoString))
getText_ :: forall error.
FromJSVal error =>
MisoString
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response MisoString))
getText_ MisoString
url [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response MisoString)))
forall a. IO (MVar a)
forall {error}.
IO (MVar (Either (Response error) (Response MisoString)))
newEmptyMVar :: IO (MVar (Either (Response error) (Response MisoString)))
FFI.fetch url "GET" Nothing textHeaders_
(putMVar mvar . Right)
(putMVar mvar . Left)
TEXT
takeMVar mvar
where
textHeaders_ :: [(MisoString, MisoString)]
textHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
accept MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
textPlain]
{-# INLINE getText_ #-}
postText_
:: FromJSVal error
=> MisoString
-> MisoString
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
postText_ :: forall error.
FromJSVal error =>
MisoString
-> MisoString
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
postText_ MisoString
url MisoString
body_ [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response ())))
forall a. IO (MVar a)
forall {error}. IO (MVar (Either (Response error) (Response ())))
newEmptyMVar :: IO (MVar (Either (Response error) (Response ())))
bodyVal <- toJSVal (encode body_)
FFI.fetch url "POST" (Just bodyVal) textHeaders_
(putMVar mvar . Right)
(putMVar mvar . Left)
NONE
takeMVar mvar
where
textHeaders_ :: [(MisoString, MisoString)]
textHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
textPlain]
{-# INLINE postText_ #-}
putText_
:: FromJSVal error
=> MisoString
-> MisoString
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
putText_ :: forall error.
FromJSVal error =>
MisoString
-> MisoString
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
putText_ MisoString
url MisoString
imageBody [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response ())))
forall a. IO (MVar a)
forall {error}. IO (MVar (Either (Response error) (Response ())))
newEmptyMVar :: IO (MVar (Either (Response error) (Response ())))
body_ <- toJSVal imageBody
FFI.fetch url "PUT" (Just body_) textHeaders_
(putMVar mvar . Right)
(putMVar mvar . Left)
NONE
takeMVar mvar
where
textHeaders_ :: [(MisoString, MisoString)]
textHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
textPlain]
{-# INLINE putText_ #-}
getBlob_
:: FromJSVal error
=> MisoString
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response Blob))
getBlob_ :: forall error.
FromJSVal error =>
MisoString
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response Blob))
getBlob_ MisoString
url [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response Blob)))
forall a. IO (MVar a)
forall {error}. IO (MVar (Either (Response error) (Response Blob)))
newEmptyMVar :: IO (MVar (Either (Response error) (Response Blob)))
FFI.fetch url "GET" Nothing blobHeaders_
(putMVar mvar . Right)
(putMVar mvar . Left)
BLOB
takeMVar mvar
where
blobHeaders_ :: [(MisoString, MisoString)]
blobHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
accept MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
octetStream]
{-# INLINE getBlob_ #-}
postBlob_
:: FromJSVal error
=> MisoString
-> Blob
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
postBlob_ :: forall error.
FromJSVal error =>
MisoString
-> Blob
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
postBlob_ MisoString
url Blob
body_ [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response ())))
forall a. IO (MVar a)
forall {error}. IO (MVar (Either (Response error) (Response ())))
newEmptyMVar :: IO (MVar (Either (Response error) (Response ())))
bodyVal <- toJSVal body_
FFI.fetch url "POST" (Just bodyVal) blobHeaders_
(putMVar mvar . Right)
(putMVar mvar . Left)
NONE
takeMVar mvar
where
blobHeaders_ :: [(MisoString, MisoString)]
blobHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
octetStream]
{-# INLINE postBlob_ #-}
putBlob_
:: FromJSVal error
=> MisoString
-> Blob
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
putBlob_ :: forall error.
FromJSVal error =>
MisoString
-> Blob
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
putBlob_ MisoString
url Blob
imageBody [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response ())))
forall a. IO (MVar a)
forall {error}. IO (MVar (Either (Response error) (Response ())))
newEmptyMVar :: IO (MVar (Either (Response error) (Response ())))
body_ <- toJSVal imageBody
FFI.fetch url "PUT" (Just body_) blobHeaders_
(putMVar mvar . Right)
(putMVar mvar . Left)
NONE
takeMVar mvar
where
blobHeaders_ :: [(MisoString, MisoString)]
blobHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
octetStream]
{-# INLINE putBlob_ #-}
getFormData_
:: FromJSVal error
=> MisoString
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response FormData))
getFormData_ :: forall error.
FromJSVal error =>
MisoString
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response FormData))
getFormData_ MisoString
url [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response FormData)))
forall a. IO (MVar a)
forall {error}.
IO (MVar (Either (Response error) (Response FormData)))
newEmptyMVar :: IO (MVar (Either (Response error) (Response FormData)))
FFI.fetch url "GET" Nothing formDataHeaders_
(putMVar mvar . Right)
(putMVar mvar . Left)
FORM_DATA
takeMVar mvar
where
formDataHeaders_ :: [(MisoString, MisoString)]
formDataHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
accept MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
formData]
{-# INLINE getFormData_ #-}
postFormData_
:: FromJSVal error
=> MisoString
-> FormData
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
postFormData_ :: forall error.
FromJSVal error =>
MisoString
-> FormData
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
postFormData_ MisoString
url FormData
body_ [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response ())))
forall a. IO (MVar a)
forall {error}. IO (MVar (Either (Response error) (Response ())))
newEmptyMVar :: IO (MVar (Either (Response error) (Response ())))
bodyVal <- toJSVal body_
FFI.fetch url "POST" (Just bodyVal) formDataHeaders_
(putMVar mvar . Right)
(putMVar mvar . Left)
NONE
takeMVar mvar
where
formDataHeaders_ :: [(MisoString, MisoString)]
formDataHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
formData]
{-# INLINE postFormData_ #-}
putFormData_
:: FromJSVal error
=> MisoString
-> FormData
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
putFormData_ :: forall error.
FromJSVal error =>
MisoString
-> FormData
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
putFormData_ MisoString
url FormData
imageBody [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response ())))
forall a. IO (MVar a)
forall {error}. IO (MVar (Either (Response error) (Response ())))
newEmptyMVar :: IO (MVar (Either (Response error) (Response ())))
body_ <- toJSVal imageBody
FFI.fetch url "PUT" (Just body_) formDataHeaders_
(putMVar mvar . Right)
(putMVar mvar . Left)
NONE
takeMVar mvar
where
formDataHeaders_ :: [(MisoString, MisoString)]
formDataHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
formData]
{-# INLINE putFormData_ #-}
getArrayBuffer_
:: FromJSVal error
=> MisoString
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ArrayBuffer))
getArrayBuffer_ :: forall error.
FromJSVal error =>
MisoString
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ArrayBuffer))
getArrayBuffer_ MisoString
url [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response ArrayBuffer)))
forall a. IO (MVar a)
forall {error}.
IO (MVar (Either (Response error) (Response ArrayBuffer)))
newEmptyMVar :: IO (MVar (Either (Response error) (Response ArrayBuffer)))
FFI.fetch url "GET" Nothing arrayBufferHeaders_
(putMVar mvar . Right)
(putMVar mvar . Left)
ARRAY_BUFFER
takeMVar mvar
where
arrayBufferHeaders_ :: [(MisoString, MisoString)]
arrayBufferHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
accept MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
octetStream]
{-# INLINE getArrayBuffer_ #-}
postArrayBuffer_
:: FromJSVal error
=> MisoString
-> ArrayBuffer
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
postArrayBuffer_ :: forall error.
FromJSVal error =>
MisoString
-> ArrayBuffer
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
postArrayBuffer_ MisoString
url ArrayBuffer
body_ [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response ())))
forall a. IO (MVar a)
forall {error}. IO (MVar (Either (Response error) (Response ())))
newEmptyMVar :: IO (MVar (Either (Response error) (Response ())))
bodyVal <- toJSVal body_
FFI.fetch url "POST" (Just bodyVal) arrayBufferHeaders_
(putMVar mvar . Right)
(putMVar mvar . Left)
NONE
takeMVar mvar
where
arrayBufferHeaders_ :: [(MisoString, MisoString)]
arrayBufferHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
octetStream]
{-# INLINE postArrayBuffer_ #-}
putArrayBuffer_
:: FromJSVal error
=> MisoString
-> ArrayBuffer
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
putArrayBuffer_ :: forall error.
FromJSVal error =>
MisoString
-> ArrayBuffer
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
putArrayBuffer_ MisoString
url ArrayBuffer
arrayBuffer_ [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response ())))
forall a. IO (MVar a)
forall {error}. IO (MVar (Either (Response error) (Response ())))
newEmptyMVar :: IO (MVar (Either (Response error) (Response ())))
body_ <- toJSVal arrayBuffer_
FFI.fetch url "PUT" (Just body_) arrayBufferHeaders_
(putMVar mvar . Right)
(putMVar mvar . Left)
NONE
takeMVar mvar
where
arrayBufferHeaders_ :: [(MisoString, MisoString)]
arrayBufferHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
octetStream]
{-# INLINE putArrayBuffer_ #-}
getUint8Array_
:: FromJSVal error
=> MisoString
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response Uint8Array))
getUint8Array_ :: forall error.
FromJSVal error =>
MisoString
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response Uint8Array))
getUint8Array_ MisoString
url [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response Uint8Array)))
forall a. IO (MVar a)
forall {error}.
IO (MVar (Either (Response error) (Response Uint8Array)))
newEmptyMVar :: IO (MVar (Either (Response error) (Response Uint8Array)))
FFI.fetch url "GET" Nothing uint8ArrayHeaders_
(putMVar mvar . Right)
(putMVar mvar . Left)
BYTES
takeMVar mvar
where
uint8ArrayHeaders_ :: [(MisoString, MisoString)]
uint8ArrayHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
accept MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
octetStream]
{-# INLINE getUint8Array_ #-}
postUint8Array_
:: FromJSVal error
=> MisoString
-> Uint8Array
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
postUint8Array_ :: forall error.
FromJSVal error =>
MisoString
-> Uint8Array
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
postUint8Array_ MisoString
url Uint8Array
body_ [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response ())))
forall a. IO (MVar a)
forall {error}. IO (MVar (Either (Response error) (Response ())))
newEmptyMVar :: IO (MVar (Either (Response error) (Response ())))
bodyVal <- toJSVal body_
FFI.fetch url "POST" (Just bodyVal) uint8ArrayHeaders_
(putMVar mvar . Right)
(putMVar mvar . Left)
NONE
takeMVar mvar
where
uint8ArrayHeaders_ :: [(MisoString, MisoString)]
uint8ArrayHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
octetStream]
{-# INLINE postUint8Array_ #-}
putUint8Array_
:: FromJSVal error
=> MisoString
-> Uint8Array
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
putUint8Array_ :: forall error.
FromJSVal error =>
MisoString
-> Uint8Array
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
putUint8Array_ MisoString
url Uint8Array
uint8Array_ [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response ())))
forall a. IO (MVar a)
forall {error}. IO (MVar (Either (Response error) (Response ())))
newEmptyMVar :: IO (MVar (Either (Response error) (Response ())))
body_ <- toJSVal uint8Array_
FFI.fetch url "PUT" (Just body_) uint8ArrayHeaders_
(putMVar mvar . Right)
(putMVar mvar . Left)
NONE
takeMVar mvar
where
uint8ArrayHeaders_ :: [(MisoString, MisoString)]
uint8ArrayHeaders_ = [(MisoString, MisoString)]
-> [(MisoString, MisoString)] -> [(MisoString, MisoString)]
forall k a. Ord k => [(k, a)] -> [(k, a)] -> [(k, a)]
biasHeaders [(MisoString, MisoString)]
headers_ [MisoString
contentType MisoString -> MisoString -> (MisoString, MisoString)
forall k v. k -> v -> (k, v)
=: MisoString
octetStream]
{-# INLINE putUint8Array_ #-}
postImage_
:: FromJSVal error
=> MisoString
-> Image
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
postImage_ :: forall error.
FromJSVal error =>
MisoString
-> Image
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
postImage_ MisoString
url Image
body_ [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response ())))
forall a. IO (MVar a)
forall {error}. IO (MVar (Either (Response error) (Response ())))
newEmptyMVar :: IO (MVar (Either (Response error) (Response ())))
bodyVal <- toJSVal body_
FFI.fetch url "POST" (Just bodyVal) headers_
(putMVar mvar . Right)
(putMVar mvar . Left)
NONE
takeMVar mvar
{-# INLINE postImage_ #-}
putImage_
:: FromJSVal error
=> MisoString
-> Image
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
putImage_ :: forall error.
FromJSVal error =>
MisoString
-> Image
-> [(MisoString, MisoString)]
-> IO (Either (Response error) (Response ()))
putImage_ MisoString
url Image
imageBody [(MisoString, MisoString)]
headers_ = do
mvar <- IO (MVar (Either (Response error) (Response ())))
forall a. IO (MVar a)
forall {error}. IO (MVar (Either (Response error) (Response ())))
newEmptyMVar :: IO (MVar (Either (Response error) (Response ())))
body_ <- toJSVal imageBody
FFI.fetch url "PUT" (Just body_) headers_
(putMVar mvar . Right)
(putMVar mvar . Left)
NONE
takeMVar mvar
{-# INLINE putImage_ #-}