http-barf-0.1.1.0: a library to make http requests without worrying much
Safe HaskellSafe-Inferred
LanguageGHC2021

Network.HTTP.Barf

Description

Barf is a http client library that tries to make scripting http requests as easy as possible. It provides a monoidal combinator library that should not clash with Prelude imports. It delegates to and includes for convenience the great aeson library for e.g. decoding of json

Example Usage:

>>> :set -XOverloadedLists
>>> decode @Value <$> get_ "https://jsonplaceholder.typicode.com/posts" [q_ "userId" "1"]
 Just (Array [Object (fromList [("body",String ...
Synopsis

prepare a request

get_ Source #

Arguments

:: MonadIO m 
=> String

the url to connect to

-> Req

the modifier(s) to the request

-> m LazyByteString 

creates a GET request, use it like

get_ "http://localhost:8080" []

head_ Source #

Arguments

:: MonadIO m 
=> String

the url to connect to

-> Req

the modifier(s) to the request

-> m LazyByteString 

creates a HEAD request, use it like

head_ "http://localhost:8080" []

post_ Source #

Arguments

:: MonadIO m 
=> String

the url to connect to

-> Req

the modifier(s) to the request

-> m LazyByteString 

creates a POST request, use it like

post_ "http://localhost:8080" []

put_ Source #

Arguments

:: MonadIO m 
=> String

the url to connect to

-> Req

the modifier(s) to the request

-> m LazyByteString 

creates a PUT request, use it like

put_ "http://localhost:8080" []

delete_ Source #

Arguments

:: MonadIO m 
=> String

the url to connect to

-> Req

the modifier(s) to the request

-> m LazyByteString 

creates a DELETE request, use it like

delete_ "http://localhost:8080" []

modify an http request

the type of http request modifications

data Req Source #

The type of request modifications. The most important features of this type are the Monoid, Semigroup and IsList instances.

Instances

Instances details
Monoid Req Source #

the empty Req does nothing to the "base" request

Instance details

Defined in Network.HTTP.Barf.Internal

Methods

mempty :: Req #

mappend :: Req -> Req -> Req #

mconcat :: [Req] -> Req #

Semigroup Req Source #

combining to Reqs composes the extensions to the request

Instance details

Defined in Network.HTTP.Barf.Internal

Methods

(<>) :: Req -> Req -> Req #

sconcat :: NonEmpty Req -> Req #

stimes :: Integral b => b -> Req -> Req #

IsList Req Source #

An IsList instance for Req makes it easy to combine multiple Reqs monoidally by passing them in list syntax. The idea is that it composes all of the request extensions in the list it gets passed

Even though toList = singleton, this instance does adhere to the laws of the IsList type class

Instance details

Defined in Network.HTTP.Barf.Internal

Associated Types

type Item Req #

Methods

fromList :: [Item Req] -> Req #

fromListN :: Int -> [Item Req] -> Req #

toList :: Req -> [Item Req] #

type Item Req Source # 
Instance details

Defined in Network.HTTP.Barf.Internal

type Item Req = Req

http request modifiers

q_ Source #

Arguments

:: String

the name of the query param

-> String

the value of the query param

-> Req 

q_ like "query"

h_ Source #

Arguments

:: String

the name of the header

-> String

the value of the header

-> Req 

h_ like "header"

j_ Source #

Arguments

:: ToJSON a 
=> a

the value of the json body

-> Req 

j_ like "json"

if the json body is already set, it will be overwritten

v_ Source #

Arguments

:: Value

the value of the json body

-> Req 

v_ like "value"

this is a convenience helper for using j_ specialised to 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

debugging helpers

inspectRequest_ :: Req Source #

print the request before dispatching, useful for debugging

dryRun_ :: Req Source #

when set, do not execute the request

useful reexports

module Data.Aeson