| Safe Haskell | None |
|---|---|
| Language | Haskell98 |
Yesod.Core.Json
- defaultLayoutJson :: (Yesod site, ToJSON a) => WidgetFor site () -> HandlerFor site a -> HandlerFor site TypedContent
- jsonToRepJson :: (Monad m, ToJSON a) => a -> m Value
- returnJson :: (Monad m, ToJSON a) => a -> m Value
- returnJsonEncoding :: (Monad m, ToJSON a) => a -> m Encoding
- provideJson :: (Monad m, ToJSON a) => a -> Writer (Endo [ProvidedRep m]) ()
- parseJsonBody :: (MonadHandler m, FromJSON a) => m (Result a)
- parseCheckJsonBody :: (MonadHandler m, FromJSON a) => m (Result a)
- parseJsonBody_ :: (MonadHandler m, FromJSON a) => m a
- requireJsonBody :: (MonadHandler m, FromJSON a) => m a
- requireCheckJsonBody :: (MonadHandler m, FromJSON a) => m a
- data Value :: *
- class ToJSON a where
- class FromJSON a where
- array :: ToJSON a => [a] -> Value
- object :: [Pair] -> Value
- (.=) :: KeyValue kv => forall v. ToJSON v => Text -> v -> kv
- (.:) :: FromJSON a => Object -> Text -> Parser a
- jsonOrRedirect :: (MonadHandler m, ToJSON a) => Route (HandlerSite m) -> a -> m Value
- jsonEncodingOrRedirect :: (MonadHandler m, ToJSON a) => Route (HandlerSite m) -> a -> m Encoding
- acceptsJson :: MonadHandler m => m Bool
Convert from a JSON value
Arguments
| :: (Yesod site, ToJSON a) | |
| => WidgetFor site () | HTML |
| -> HandlerFor site a | JSON |
| -> HandlerFor site 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
returnJsonEncoding :: (Monad m, ToJSON a) => a -> m Encoding Source #
Convert a value to a JSON representation via aeson's toEncoding function.
Since: 1.4.21
provideJson :: (Monad m, ToJSON a) => a -> Writer (Endo [ProvidedRep m]) () Source #
Provide a JSON representation for usage with selectReps, using aeson's
toJSON (aeson >= 0.11: toEncoding) 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
parseCheckJsonBody :: (MonadHandler m, FromJSON a) => m (Result a) Source #
Same as parseJsonBody, but ensures that the mime type indicates
JSON content.
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.
requireCheckJsonBody :: (MonadHandler m, FromJSON a) => m a Source #
Same as requireJsonBody, but ensures that the mime type
indicates JSON content.
Produce JSON values
Instances
| Eq Value | |
| Data Value | |
| Read Value | |
| Show Value | |
| IsString Value | |
| Generic Value | |
| Lift Value | |
| Hashable Value | |
| NFData Value | |
| ToJavascript Value | |
| ToJSON Value | |
| KeyValue Pair | |
| FromJSON Value | |
| ToTypedContent Value Source # | |
| ToTypedContent Encoding Source # | |
| HasContentType Value Source # | |
| HasContentType Encoding Source # | |
| ToContent Value Source # | |
| ToContent Encoding Source # | |
| FromString Value | |
| FromString Encoding | |
| GKeyValue Encoding Series | |
| FromPairs Encoding Series | |
| GToJSON Value arity (U1 *) | |
| GToJSON Encoding arity (U1 *) | |
| ToJSON1 f => GToJSON Value One (Rec1 * f) | |
| ToJSON1 f => GToJSON Encoding One (Rec1 * f) | |
| ToJSON a => GToJSON Value arity (K1 * i a) | |
| (WriteProduct arity a, WriteProduct arity b, ProductSize a, ProductSize b) => GToJSON Value arity ((:*:) * a b) | |
| ToJSON a => GToJSON Encoding arity (K1 * i a) | |
| (EncodeProduct arity a, EncodeProduct arity b) => GToJSON Encoding arity ((:*:) * a b) | |
| (ToJSON1 f, GToJSON Value One g) => GToJSON Value One ((:.:) * * f g) | |
| (ToJSON1 f, GToJSON Encoding One g) => GToJSON Encoding One ((:.:) * * f g) | |
| ToJSON v => GKeyValue v (DList Pair) | |
| FromPairs Value (DList Pair) | |
| (GToJSON Value arity a, ConsToJSON Value arity a, Constructor Meta c) => SumToJSON' * TwoElemArray Value arity (C1 * c a) | |
| (GToJSON Encoding arity a, ConsToJSON Encoding arity a, Constructor Meta c) => SumToJSON' * TwoElemArray Encoding arity (C1 * c a) | |
| type Rep Value | |
Instances
Instances
Convenience functions
Arguments
| :: (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.
jsonEncodingOrRedirect Source #
Arguments
| :: (MonadHandler m, ToJSON a) | |
| => Route (HandlerSite m) | Redirect target |
| -> a | Data to send via JSON |
| -> m Encoding |
jsonEncodingOrRedirect 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. @since 1.4.21
acceptsJson :: MonadHandler m => m Bool Source #
Returns True if the client prefers application/json as
indicated by the Accept HTTP header.