From f928e1b98891d7a2010d7f297a17a1f14f6ee19b Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Sun, 5 Jun 2022 20:12:57 +0100 Subject: [PATCH] Add documentation --- src/HTTPurple/Cont.purs | 1 + src/HTTPurple/Json.purs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/HTTPurple/Cont.purs b/src/HTTPurple/Cont.purs index 6b2cace..bba1340 100644 --- a/src/HTTPurple/Cont.purs +++ b/src/HTTPurple/Cont.purs @@ -6,5 +6,6 @@ import Prelude import Control.Monad.Cont (ContT, runContT) +-- | Run the continuation usingCont :: forall output m. Applicative m => ContT output m output -> m output usingCont = flip runContT pure diff --git a/src/HTTPurple/Json.purs b/src/HTTPurple/Json.purs index 909683f..543c749 100644 --- a/src/HTTPurple/Json.purs +++ b/src/HTTPurple/Json.purs @@ -47,9 +47,15 @@ fromJsonContinuation (JsonDecoder decode) errorHandler body handler = do defaultErrorHandler :: forall (t47 :: Type) (m :: Type -> Type). MonadAff m => t47 -> m Response defaultErrorHandler = const $ badRequest' jsonHeaders "" +-- | Parse the `RequestBody` as json using the provided `JsonDecoder`. +-- | If it fails, the error handler is called. +-- | Returns a continuation fromJsonE :: forall (err :: Type) (json :: Type). JsonDecoder err json -> (err -> ResponseM) -> RequestBody -> ContT Response Aff json fromJsonE driver errorHandler body = ContT $ (fromJsonContinuation driver errorHandler body) +-- | Parse the `RequestBody` as json using the provided `JsonDecoder`. +-- | If it fails, an empty bad request is returned +-- | Returns a continuation fromJson :: forall (err :: Type) (json :: Type). JsonDecoder err json -> RequestBody -> ContT Response Aff json fromJson driver = fromJsonE driver defaultErrorHandler