Haskell Library - req
Notes on req
Snippets
-
Basic post requestUsing
req ==3.13.0
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Monad.IO.Class (MonadIO (liftIO))
import Data.Aeson (FromJSON, ToJSON, Value)
import Data.Text (Text)
import GHC.Generics (Generic)
import Network.HTTP.Req
( IgnoreResponse,
POST (POST),
ReqBodyJson (ReqBodyJson),
defaultHttpConfig,
http,
ignoreResponse,
jsonResponse,
port,
req,
responseBody,
runReq,
(/:),
)
import Prelude
data MyData = MyData
{ message :: Text,
datetime :: Text
}
deriving (Show, Generic)
instance ToJSON MyData
instance FromJSON MyData
main :: IO IgnoreResponse
main = runReq defaultHttpConfig $ do
let myData =
MyData
{ message = "haskell",
datetime = "2023-10-14T14:20:00"
}
req
POST
(http "localhost" /: "api" /: "notification")
(ReqBodyJson myData)
ignoreResponse
(port 4000)