[chore] make ready for publishing
This commit is contained in:
parent
0c6cf2f58f
commit
b511ebfc8b
|
@ -1,5 +1,5 @@
|
||||||
# Revision history for http-barf
|
# 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
|
||||||
|
|
8
README.md
Normal file
8
README.md
Normal file
|
@ -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.
|
|
@ -2,8 +2,11 @@ cabal-version: 3.4
|
||||||
name: http-barf
|
name: http-barf
|
||||||
version: 0.1.0.0
|
version: 0.1.0.0
|
||||||
synopsis: a library to make http requests without worrying much
|
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
|
homepage: https://git.mangoiv.com/mangoiv/http-barf
|
||||||
license: AGPL-3.0-or-later
|
license: AGPL-3.0-or-later
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
|
@ -13,9 +16,9 @@ maintainer: contact@mangoiv.com
|
||||||
-- copyright:
|
-- copyright:
|
||||||
category: Network
|
category: Network
|
||||||
build-type: Simple
|
build-type: Simple
|
||||||
extra-doc-files: CHANGELOG.md
|
extra-doc-files:
|
||||||
|
CHANGELOG.md
|
||||||
-- extra-source-files:
|
README.md
|
||||||
|
|
||||||
common common-all
|
common common-all
|
||||||
ghc-options: -Wall
|
ghc-options: -Wall
|
||||||
|
|
|
@ -39,7 +39,6 @@ import Network.HTTP.Client
|
||||||
import Network.HTTP.Client.TLS (tlsManagerSettings)
|
import Network.HTTP.Client.TLS (tlsManagerSettings)
|
||||||
import System.Exit (exitFailure)
|
import System.Exit (exitFailure)
|
||||||
import System.IO (hPutStrLn, stderr)
|
import System.IO (hPutStrLn, stderr)
|
||||||
import Prelude hiding (head)
|
|
||||||
|
|
||||||
-- | a data type representing an http request
|
-- | a data type representing an http request
|
||||||
data Req' = MkReq'
|
data Req' = MkReq'
|
||||||
|
@ -54,6 +53,8 @@ data Req' = MkReq'
|
||||||
defaultReq' :: Req'
|
defaultReq' :: Req'
|
||||||
defaultReq' = MkReq' {queryParams = mempty, headers = mempty, jsonBody = Nothing, inspectRequest = False, dryRun = False}
|
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'}
|
newtype Req = MkReq {appReq :: Req' -> Req'}
|
||||||
deriving
|
deriving
|
||||||
( Semigroup
|
( Semigroup
|
||||||
|
@ -79,7 +80,7 @@ instance IsList Req where
|
||||||
get_
|
get_
|
||||||
:: MonadIO m
|
:: MonadIO m
|
||||||
=> String
|
=> String
|
||||||
-- ^ the url toiconnect to
|
-- ^ the url to connect to
|
||||||
-> Req
|
-> Req
|
||||||
-- ^ the modifier(s) to the request
|
-- ^ the modifier(s) to the request
|
||||||
-> m LazyByteString
|
-> m LazyByteString
|
||||||
|
@ -153,7 +154,7 @@ buildRequestFromReq method url req = do
|
||||||
|
|
||||||
httpWithManager :: MonadIO m => String -> String -> Req -> m LazyByteString
|
httpWithManager :: MonadIO m => String -> String -> Req -> m LazyByteString
|
||||||
httpWithManager method url req = liftIO do
|
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
|
manager <- newManager if r.secure then tlsManagerSettings else defaultManagerSettings
|
||||||
responseBody <$> httpLbs r manager
|
responseBody <$> httpLbs r manager
|
||||||
|
|
||||||
|
@ -177,7 +178,10 @@ h_ k v = MkReq \req -> req {headers = (k, v) `V.cons` req.headers}
|
||||||
|
|
||||||
-- | 'v_' like "value"
|
-- | '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_
|
v_
|
||||||
:: Value
|
:: Value
|
||||||
-- ^ the value of the json body
|
-- ^ the value of the json body
|
||||||
|
@ -186,7 +190,7 @@ v_ val = MkReq \req -> req {jsonBody = Just val}
|
||||||
|
|
||||||
-- | 'j_' like "json"
|
-- | '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_
|
j_
|
||||||
:: Aeson.ToJSON a
|
:: Aeson.ToJSON a
|
||||||
=> a
|
=> a
|
||||||
|
|
Loading…
Reference in a new issue