tvl-depot/users/Profpatsch/mailbox-org/AesonQQ.hs
Profpatsch f627ee84b3 feat(users/Profpatsch/mailbox-org): add simple request json example
Adds a simple json quasiquoter thingy.

Json can be sent to the `/mailfilter?action=update` endpoint.

Change-Id: Iba80c2ab69178e431519933c4a01cd68aaa9f637
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7839
Tested-by: BuildkiteCI
Autosubmit: Profpatsch <mail@profpatsch.de>
Reviewed-by: Profpatsch <mail@profpatsch.de>
2023-01-15 20:36:33 +00:00

23 lines
662 B
Haskell

{-# LANGUAGE TemplateHaskellQuotes #-}
module AesonQQ where
import Data.Aeson qualified as Json
import Data.Either qualified as Either
import MyPrelude
import PyF qualified
import PyF.Internal.QQ qualified as PyFConf
aesonQQ =
PyF.mkFormatter
"aesonQQ"
PyF.defaultConfig
{ PyFConf.delimiters = Just ('|', '|'),
PyFConf.postProcess = \exp -> do
-- TODO: this does not throw an error at compilation time if the json does not parse
[|
case Json.eitherDecodeStrict' @Json.Value $ textToBytesUtf8 $ stringToText $(exp) of
Left err -> error err
Right a -> a
|]
}