JSON-specific sendResponseStatus
This commit is contained in:
parent
77c614fa86
commit
6a60dac366
@ -93,6 +93,8 @@ module Yesod.Core.Handler
|
|||||||
, sendFilePart
|
, sendFilePart
|
||||||
, sendResponse
|
, sendResponse
|
||||||
, sendResponseStatus
|
, sendResponseStatus
|
||||||
|
-- ** Type specific response with custom status
|
||||||
|
, sendResponseStatusJSON
|
||||||
, sendResponseCreated
|
, sendResponseCreated
|
||||||
, sendWaiResponse
|
, sendWaiResponse
|
||||||
, sendWaiApplication
|
, sendWaiApplication
|
||||||
@ -198,6 +200,7 @@ import Network.Wai.Middleware.HttpAuth
|
|||||||
( extractBasicAuth, extractBearerAuth )
|
( extractBasicAuth, extractBearerAuth )
|
||||||
import Control.Monad.Trans.Class (lift)
|
import Control.Monad.Trans.Class (lift)
|
||||||
|
|
||||||
|
import Data.Aeson (ToJSON(..))
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Data.Text.Encoding (decodeUtf8With, encodeUtf8)
|
import Data.Text.Encoding (decodeUtf8With, encodeUtf8)
|
||||||
import Data.Text.Encoding.Error (lenientDecode)
|
import Data.Text.Encoding.Error (lenientDecode)
|
||||||
@ -575,6 +578,11 @@ sendResponse = handlerError . HCContent H.status200 . toTypedContent
|
|||||||
sendResponseStatus :: (MonadHandler m, ToTypedContent c) => H.Status -> c -> m a
|
sendResponseStatus :: (MonadHandler m, ToTypedContent c) => H.Status -> c -> m a
|
||||||
sendResponseStatus s = handlerError . HCContent s . toTypedContent
|
sendResponseStatus s = handlerError . HCContent s . toTypedContent
|
||||||
|
|
||||||
|
-- | Bypass remaining handler code and output the given JSON with the given
|
||||||
|
-- status code.
|
||||||
|
sendResponseStatusJSON :: (MonadHandler m, ToJSON a) => H.Status -> a -> m a
|
||||||
|
sendResponseStatusJSON s v = sendResponseStatus s (toJSON v)
|
||||||
|
|
||||||
-- | Send a 201 "Created" response with the given route as the Location
|
-- | Send a 201 "Created" response with the given route as the Location
|
||||||
-- response header.
|
-- response header.
|
||||||
sendResponseCreated :: MonadHandler m => Route (HandlerSite m) -> m a
|
sendResponseCreated :: MonadHandler m => Route (HandlerSite m) -> m a
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user