3PRCNKNZBBKNOSRY2VXATUP4OCOEVA2UERVRBYTKUI3BG3LP4OXAC post :: (HTTP :> es, JSON.ToJSON body) => body -> Text -> Eff es Responsepost body = send . Post (JSON.encode body)
post :: (HTTP :> es, Fail :> es, Sign :> es, JSON.ToJSON body) => body -> Text -> Eff es Responsepost body url = dokey <- send GetKeyres <- send (Exec (POST { payload = JSON.encode body, url }) key)either fail return res
get :: (HTTP :> es) => Text -> Eff es Responseget = send . GetsetKey :: (S.KeySource s, HTTP :> es) => s -> Eff es a -> Eff es asetKey key rest = send (SetKey (S.toSigner key) rest)
get :: (HTTP :> es, Fail :> es, Sign :> es) => Text -> Eff es Responseget url = dokey <- send GetKeyres <- send (Exec (GET { url }) key)either fail return res
runHTTP src = reinterpret (runReader (S.toSigner src)) $ \env -> \caseSetKey key rest -> localSeqUnlift env $ \unlift ->local (const key) (unlift rest)Post payload url -> dosigner <- askreq <- withSeqEffToIO (parse url)ask >>= execute signer(req { method = "POST" })(Just $ BS.toStrict payload)Get url -> dosigner <- askreq <- withSeqEffToIO (parse url)ask >>= execute signer req Nothingwhere
runHTTP manager = interpret $ \_ -> \caseExec req signer -> runFail $ dorequest <- withSeqEffToIO (parse req.url)case req ofGET {} -> execute signer request Nothing managerPOST { payload } -> execute signer(request { method = "POST" })(Just $ BS.toStrict payload)managerwhere
-- Share a single HTTP client between all threads using the HTTP effect.-- We don't evaluate the HTTP effect in the global handler, because we-- don't want failures to propagate to the main thread. This handler must-- not fail unless there is something catastrophically wrong.. runReader manager