Safe Haskell | None |
---|---|
Language | Haskell98 |
- defaultLayoutJson :: (Yesod site, ToJSON a) => WidgetT site IO () -> HandlerT site IO a -> HandlerT site IO TypedContent
- jsonToRepJson :: (Monad m, ToJSON a) => a -> m Value
- returnJson :: (Monad m, ToJSON a) => a -> m Value
- provideJson :: (Monad m, ToJSON a) => a -> Writer (Endo [ProvidedRep m]) ()
- parseJsonBody :: (MonadHandler m, FromJSON a) => m (Result a)
- parseJsonBody_ :: (MonadHandler m, FromJSON a) => m a
- requireJsonBody :: (MonadHandler m, FromJSON a) => m a
- data Value :: *
- class ToJSON a where
- class FromJSON a where
- array :: ToJSON a => [a] -> Value
- object :: [Pair] -> Value
- (.=) :: ToJSON a => Text -> a -> Pair
- (.:) :: FromJSON a => Object -> Text -> Parser a
- jsonOrRedirect :: (MonadHandler m, ToJSON a) => Route (HandlerSite m) -> a -> m Value
- acceptsJson :: MonadHandler m => m Bool
Convert from a JSON value
:: (Yesod site, ToJSON a) | |
=> WidgetT site IO () | HTML |
-> HandlerT site IO a | JSON |
-> HandlerT site IO TypedContent |
Provide both an HTML and JSON representation for a piece of
data, using the default layout for the HTML output
(defaultLayout
).
Since: 0.3.0
jsonToRepJson :: (Monad m, ToJSON a) => a -> m Value Source
Deprecated: Use returnJson instead
Wraps a data type in a RepJson
. The data type must
support conversion to JSON via ToJSON
.
Since: 0.3.0
returnJson :: (Monad m, ToJSON a) => a -> m Value Source
Convert a value to a JSON representation via aeson's toJSON
function.
Since 1.2.1
provideJson :: (Monad m, ToJSON a) => a -> Writer (Endo [ProvidedRep m]) () Source
Provide a JSON representation for usage with selectReps
, using aeson's
toJSON
function to perform the conversion.
Since 1.2.1
Convert to a JSON value
parseJsonBody :: (MonadHandler m, FromJSON a) => m (Result a) Source
Parse the request body to a data type as a JSON value. The
data type must support conversion from JSON via FromJSON
.
If you want the raw JSON value, just ask for a
.Result
Value
Note that this function will consume the request body. As such, calling it twice will result in a parse error on the second call, since the request body will no longer be available.
Since: 0.3.0
parseJsonBody_ :: (MonadHandler m, FromJSON a) => m a Source
Deprecated: Use requireJsonBody instead
Same as parseJsonBody
, but return an invalid args response on a parse
error.
requireJsonBody :: (MonadHandler m, FromJSON a) => m a Source
Same as parseJsonBody
, but return an invalid args response on a parse
error.
Produce JSON values
data Value :: *
class ToJSON a where
Nothing
class FromJSON a where
Nothing
Convenience functions
:: (MonadHandler m, ToJSON a) | |
=> Route (HandlerSite m) | Redirect target |
-> a | Data to send via JSON |
-> m Value |
jsonOrRedirect simplifies the scenario where a POST handler sends a different response based on Accept headers:
- 200 with JSON data if the client prefers
application/json
(e.g. AJAX, seeacceptsJSON
).- 3xx otherwise, following the PRG pattern.
acceptsJson :: MonadHandler m => m Bool Source
Returns True
if the client prefers application/json
as
indicated by the Accept
HTTP header.