diff --git a/README.md b/README.md index b424589..3408041 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,15 @@ combinator library. You may use it if you just have to vomit out a quick script and don't want to deal with all the complexities of involving a library that provides more features or more safety guarantees. + +## Example + +```haskell +λ GHCi ~ res <- get_ "https://jsonplaceholder.typicode.com/posts" [q_ "userId" "1"] +res :: Data.ByteString.Lazy.Internal.LazyByteString +(0.40 secs, 6,838,760 bytes) +λ GHCi ~ decode @Value res +Just (Array [Object (fromList [("body",String "quia et suscipit\nsuscipit ... +it :: Maybe Value +(0.01 secs, 3,324,080 bytes) +``` diff --git a/http-barf.cabal b/http-barf.cabal index aef94f0..cf95c54 100644 --- a/http-barf.cabal +++ b/http-barf.cabal @@ -47,6 +47,7 @@ library DataKinds DerivingVia OverloadedRecordDot + OverloadedStrings TypeFamilies test-suite http-barf-test diff --git a/src/Network/HTTP/Barf/Internal.hs b/src/Network/HTTP/Barf/Internal.hs index 206260a..deed1e0 100644 --- a/src/Network/HTTP/Barf/Internal.hs +++ b/src/Network/HTTP/Barf/Internal.hs @@ -27,6 +27,7 @@ import Control.Monad (when) import Control.Monad.IO.Class (MonadIO (liftIO)) import Data.Aeson (Value) import Data.Aeson qualified as Aeson +import Data.ByteString (StrictByteString) import Data.ByteString.Char8 qualified as BS8 import Data.ByteString.Lazy (LazyByteString) import Data.List qualified as List @@ -134,12 +135,12 @@ post_ -> m LazyByteString post_ = httpWithManager "POST" -buildRequestFromReq :: String -> String -> Req' -> IO Request +buildRequestFromReq :: StrictByteString -> String -> Req' -> IO Request buildRequestFromReq method url req = do r <- setQueryString (foldMap (\(s, s') -> [(BS8.pack s, Just (BS8.pack s'))]) req.queryParams) . (\r -> r {requestBody = RequestBodyLBS $ Aeson.encode req.jsonBody}) - . (\r -> r {method = BS8.pack method}) + . (\r -> r {method = method}) <$> parseRequest url let err = hPutStrLn stderr when req.inspectRequest do @@ -152,7 +153,7 @@ buildRequestFromReq method url req = do exitFailure pure r -httpWithManager :: MonadIO m => String -> String -> Req -> m LazyByteString +httpWithManager :: MonadIO m => StrictByteString -> String -> Req -> m LazyByteString httpWithManager method url req = liftIO do r <- buildRequestFromReq method url $ req.appReq defaultReq' manager <- newManager if r.secure then tlsManagerSettings else defaultManagerSettings