packages feed

polysemy-req (empty) → 0.1.0

raw patch · 2 files changed

+101/−0 lines, 2 filesdep +basedep +polysemydep +req

Dependencies added: base, polysemy, req

Files

+ polysemy-req.cabal view
@@ -0,0 +1,23 @@+cabal-version: 2.4+name:          polysemy-req+version:       0.1.0+license:       BSD-3-Clause+maintainer:    themorrowm@gmail.com+author:        Morrow+homepage:      https://github.com/morrowm/polysemy-req+bug-reports:   https://github.com/morrowm/polysemy-req/issues+synopsis:      Polysemy effect for req+description:+  A basic effect for making req requests inside a polysemy application. ++category:      Network, Web+build-type:    Simple++library+  exposed-modules:  Polysemy.Req+  hs-source-dirs:   src+  default-language: Haskell2010+  build-depends:+    , base      >=4.14 && <5+    , polysemy  >=1.3  && <1.6+    , req       >=2.1  && <3.10
+ src/Polysemy/Req.hs view
@@ -0,0 +1,78 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE UndecidableInstances #-}+{-# OPTIONS_GHC -Wno-orphans #-}++-- |+-- Module      :  Polysemy.Req+-- Copyright   :  (C) 2021 Morrow+-- License     :  BSD3-3-Clause+-- Maintainer  :  Morrow <themorrowm@gmail.com>+-- "Network.HTTP.Req" adapted for use with polysemy.+module Polysemy.Req+  ( -- * Effect+    Req (..),++    -- * Actions+    req,++    -- * Interpretations+    interpretReq,+    interpretReqWith,++    -- * Re-exports+    module Network.HTTP.Req,+  )+where++import Data.Proxy+import Network.HTTP.Req hiding (MonadHttp, Req, req, req', reqBr, reqCb, runReq)+import qualified Network.HTTP.Req as R+import Polysemy++-- | An effect for making http 'Network.HTTP.Req.req'uests.+-- @since 0.1.0+data Req m response where+  Req ::+    ( HttpMethod method,+      HttpBody body,+      HttpResponse response,+      HttpBodyAllowed (AllowsBody method) (ProvidesBody body)+    ) =>+    -- | HTTP method+    method ->+    -- | 'Url'—location of resource+    Url scheme ->+    -- | Body of the request+    body ->+    -- | A hint how to interpret response+    Proxy response ->+    -- | Collection of optional parameters+    Option scheme ->+    -- | Response+    Req m response++-- | See 'Network.HTTP.Req.req'.+-- @since 0.1.0+makeSem ''Req++-- | Run a 'Req' effect with the 'Network.HTTP.Req.defaultHttpConfig'.+-- @since 0.1.0+interpretReq :: Member (Embed IO) r => InterpreterFor Req r+interpretReq = interpretReqWith defaultHttpConfig++-- | Run a 'Req' effect with a custom 'Network.HTTP.Req.HttpConfig'.+-- @since 0.1.0+interpretReqWith :: Member (Embed IO) r => HttpConfig -> InterpreterFor Req r+interpretReqWith cfg = interpret $ \case+  Req m u b p o -> embed @IO $ R.runReq cfg $ R.req @R.Req m u b p o