diff --git a/CHANGELOG.md b/CHANGELOG.md index 8989eed..2bf2e25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # Revision history for http-barf -## 0.1.0.0 -- YYYY-mm-dd +## 0.1.0.0 -- 2024-07-21 -* First version. Released on an unsuspecting world. +* initial support for sending simple http requests with monoidal interface diff --git a/README.md b/README.md new file mode 100644 index 0000000..54b7bfb --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# http barf + +HTTP barf is a dead simple library to make http requests. It provides helper functions to use different http methods, it supports +both insecure and secure connections without having to deal with managers and the requests can be trivially modified using a monoidal +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. diff --git a/http-barf.cabal b/http-barf.cabal index 8c0f59c..aef94f0 100644 --- a/http-barf.cabal +++ b/http-barf.cabal @@ -2,8 +2,11 @@ cabal-version: 3.4 name: http-barf version: 0.1.0.0 synopsis: a library to make http requests without worrying much +description: + a dead simple library to make http requests. It provides helper functions to use different http methods, it supports + both insecure and secure connections without having to deal with managers and the requests can be trivially modified using a monoidal + combinator library --- description: homepage: https://git.mangoiv.com/mangoiv/http-barf license: AGPL-3.0-or-later license-file: LICENSE @@ -13,9 +16,9 @@ maintainer: contact@mangoiv.com -- copyright: category: Network build-type: Simple -extra-doc-files: CHANGELOG.md - --- extra-source-files: +extra-doc-files: + CHANGELOG.md + README.md common common-all ghc-options: -Wall diff --git a/src/Network/HTTP/Barf/Internal.hs b/src/Network/HTTP/Barf/Internal.hs index 0a06d9d..eec9c47 100644 --- a/src/Network/HTTP/Barf/Internal.hs +++ b/src/Network/HTTP/Barf/Internal.hs @@ -39,7 +39,6 @@ import Network.HTTP.Client import Network.HTTP.Client.TLS (tlsManagerSettings) import System.Exit (exitFailure) import System.IO (hPutStrLn, stderr) -import Prelude hiding (head) -- | a data type representing an http request data Req' = MkReq' @@ -54,6 +53,8 @@ data Req' = MkReq' defaultReq' :: Req' defaultReq' = MkReq' {queryParams = mempty, headers = mempty, jsonBody = Nothing, inspectRequest = False, dryRun = False} +-- | The type of request modifications. +-- The most important features of this type are the 'Monoid', 'Semigroup' and 'IsList' instances. newtype Req = MkReq {appReq :: Req' -> Req'} deriving ( Semigroup @@ -79,7 +80,7 @@ instance IsList Req where get_ :: MonadIO m => String - -- ^ the url toiconnect to + -- ^ the url to connect to -> Req -- ^ the modifier(s) to the request -> m LazyByteString @@ -153,7 +154,7 @@ buildRequestFromReq method url req = do httpWithManager :: MonadIO m => String -> String -> Req -> m LazyByteString httpWithManager method url req = liftIO do - r <- buildRequestFromReq method url $ appReq req defaultReq' + r <- buildRequestFromReq method url $ req.appReq defaultReq' manager <- newManager if r.secure then tlsManagerSettings else defaultManagerSettings responseBody <$> httpLbs r manager @@ -177,7 +178,10 @@ h_ k v = MkReq \req -> req {headers = (k, v) `V.cons` req.headers} -- | 'v_' like "value" -- --- if the json body is already set, it *will be overwritten* +-- this is a convenience helper for using @'j_' @Value@. It is useful +-- if you just want to quickly build a json body for your request. +-- +-- if the json body is already set, it /will be overwritten/ v_ :: Value -- ^ the value of the json body @@ -186,7 +190,7 @@ v_ val = MkReq \req -> req {jsonBody = Just val} -- | 'j_' like "json" -- --- if the json body is already set, it *will be overwritten* +-- if the json body is already set, it /will be overwritten/ j_ :: Aeson.ToJSON a => a