yesod-core-0.9.4.1: Creation of type-safe, RESTful web applications.

Yesod.Content

Contents

- Content
- Mime types
  - Data type
- Utilities
- Representations
  - Specific content types
- Utilities

Synopsis

- data Content
  - = ContentBuilder Builder (Maybe Int)
  - | ContentEnum (forall a. Enumerator Builder IO a)
  - | ContentFile FilePath (Maybe FilePart)
- emptyContent :: Content
- class ToContent a where
  - toContent :: a -> Content
- type ContentType = ByteString
- typeHtml :: ContentType
- typePlain :: ContentType
- typeJson :: ContentType
- typeXml :: ContentType
- typeAtom :: ContentType
- typeRss :: ContentType
- typeJpeg :: ContentType
- typePng :: ContentType
- typeGif :: ContentType
- typeJavascript :: ContentType
- typeCss :: ContentType
- typeFlv :: ContentType
- typeOgv :: ContentType
- typeOctet :: ContentType
- simpleContentType :: ContentType -> ContentType
- type ChooseRep = [ContentType] -> IO (ContentType, Content)
- class HasReps a where
  - chooseRep :: a -> ChooseRep
- defChooseRep :: [(ContentType, a -> IO Content)] -> a -> ChooseRep
- newtype RepHtml = RepHtml Content
- newtype RepJson = RepJson Content
- data RepHtmlJson = RepHtmlJson Content Content
- newtype RepPlain = RepPlain Content
- newtype RepXml = RepXml Content
- formatW3 :: UTCTime -> Text
- formatRFC1123 :: UTCTime -> Text
- formatRFC822 :: UTCTime -> Text

# Content

data Content

Constructors

ContentBuilder Builder (Maybe Int) | The content and optional content length.
ContentEnum (forall a. Enumerator Builder IO a) |
ContentFile FilePath (Maybe FilePart) |

Instances

IsString Content |
HasReps ChooseRep |
HasReps [(ContentType, Content)] |
HasReps (ContentType, Content) |

emptyContent :: Content

Zero-length enumerator.

class ToContent a where

Anything which can be converted into `Content`. Most of the time, you will want to use the `ContentBuilder` constructor. An easier approach will be to use a pre-defined `toContent` function, such as converting your data into a lazy bytestring and then calling `toContent` on that.

Please note that the built-in instances for lazy data structures (`String`, lazy `ByteString`, lazy `Text` and `Html`) will not automatically include the content length for the `ContentBuilder` constructor.

Methods

toContent :: a -> Content

Instances

ToContent String |
ToContent ByteString |
ToContent Builder |
ToContent Text |
ToContent Text |
ToContent ByteString |
ToContent Html |

# Mime types

## Data type

type ContentType = ByteString

typeHtml :: ContentType

typePlain :: ContentType

typeJson :: ContentType

typeXml :: ContentType

typeAtom :: ContentType

typeRss :: ContentType

typeJpeg :: ContentType

typePng :: ContentType

typeGif :: ContentType

typeJavascript :: ContentType

typeCss :: ContentType

typeFlv :: ContentType

typeOgv :: ContentType

typeOctet :: ContentType

# Utilities

simpleContentType :: ContentType -> ContentType

Removes "extra" information at the end of a content type string. In particular, removes everything after the semicolon, if present.

For example, "text/html; charset=utf-8" is commonly used to specify the character encoding for HTML data. This function would return "text/html".

# Representations

type ChooseRep

Arguments

= [ContentType] | list of content-types user accepts, ordered by preference
-> IO (ContentType, Content) |

A function which gives targetted representations of content based on the content-types the user accepts.

class HasReps a where

Any type which can be converted to representations.

Methods

chooseRep :: a -> ChooseRep

Instances

HasReps () |
HasReps RepXml |
HasReps RepPlain |
HasReps RepHtmlJson |
HasReps RepJson |
HasReps RepHtml |
HasReps ChooseRep |
HasReps [(ContentType, Content)] |
HasReps (ContentType, Content) |

defChooseRep :: [(ContentType, a -> IO Content)] -> a -> ChooseRep

A helper method for generating `HasReps` instances.

This function should be given a list of pairs of content type and conversion functions. If none of the content types match, the first pair is used.

## Specific content types

newtype RepHtml

Constructors

RepHtml Content |

Instances

HasReps RepHtml |

newtype RepJson

Constructors

RepJson Content |

Instances

HasReps RepJson |

data RepHtmlJson

Constructors

RepHtmlJson Content Content |

Instances

HasReps RepHtmlJson |

newtype RepPlain

Constructors

RepPlain Content |

Instances

HasReps RepPlain |

newtype RepXml

Constructors

RepXml Content |

Instances

HasReps RepXml |

# Utilities

formatW3 :: UTCTime -> Text

Format a `UTCTime` in W3 format.

formatRFC1123 :: UTCTime -> Text

Format as per RFC 1123.

formatRFC822 :: UTCTime -> Text

Format as per RFC 822.