Links
Links to tutorials, blog posts, etc.
Imports
import qualified Network.HTTP.Req as R
Usage
[ see the hackage page for a commented example ]
Gotchas
The req function uses type tricks that make [R.GET, R.PUT] not type-check. If you want to pass around request parameters use a GADT like:
-- | A Request to be compiled into an IO action. Does not specify return type
data Request where
Delete :: R.Url 'R.Https -> Option -> Request
Get :: R.Url 'R.Https -> Option -> Request
Patch :: R.HttpBody a => R.Url 'R.Https -> a -> Option -> Request
Put :: R.HttpBody a => R.Url 'R.Https -> a -> Option -> Request
Post :: R.HttpBody a => R.Url 'R.Https -> a -> Option -> Request
The library throws exceptions on non-2XX response codes (eg 404). If this is not desired edit
httpConfigCheckResponse to something like:
instance R.MonadHttp MyCustomIOMonad where -- or just IO
-- :: R.MonadHttp m => R.HttpException -> m a
handleHttpException = throwIO
-- :: Req HttpConfig
getHttpConfig = pure $ def { R.httpConfigCheckResponse = \_ _ _ -> Nothing }