[feat] no unnecessary conversion, add more docs in README
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
d5d506ffc6
commit
749669dd23
12
README.md
12
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)
|
||||
```
|
||||
|
|
|
@ -47,6 +47,7 @@ library
|
|||
DataKinds
|
||||
DerivingVia
|
||||
OverloadedRecordDot
|
||||
OverloadedStrings
|
||||
TypeFamilies
|
||||
|
||||
test-suite http-barf-test
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue