Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module contains a collection of some of the Internet Media or Mime types and class to serialize and deserialize them. At the moment we only support a small set but its possible to write own custom types and provide the required instances.
Synopsis
- class HasMediaType ctyp => MediaEncode ctyp a where
- mediaEncode :: sing ctyp -> a -> ByteString
- class HasMediaType ctyp => MediaDecode ctyp a where
- mediaDecode :: sing ctyp -> ByteString -> Either DecodeError a
- class HasMediaType ctyp where
- mediaType :: sing ctyp -> MediaType
- mediaTypes :: sing ctyp -> NonEmpty MediaType
- newtype DecodeError = DecodeError {}
- data FormUrlEncoded
- data OctetStream
- data PlainText
- data JSON
- eitherDecodeLenient :: FromJSON a => ByteString -> Either String a
- data MediaType
- (//) :: ByteString -> ByteString -> MediaType
- matches :: Accept a => a -> a -> Bool
- parseAccept :: Accept a => ByteString -> Maybe a
Documentation
class HasMediaType ctyp => MediaEncode ctyp a where Source #
mediaEncode :: sing ctyp -> a -> ByteString Source #
Instances
ToForm a => MediaEncode FormUrlEncoded a Source # | |
Defined in Hreq.Core.API.MediaType mediaEncode :: sing FormUrlEncoded -> a -> ByteString Source # | |
MediaEncode OctetStream ByteString Source # | |
Defined in Hreq.Core.API.MediaType mediaEncode :: sing OctetStream -> ByteString -> ByteString Source # | |
MediaEncode OctetStream ByteString Source # | |
Defined in Hreq.Core.API.MediaType mediaEncode :: sing OctetStream -> ByteString -> ByteString0 Source # | |
Show a => MediaEncode PlainText a Source # | |
Defined in Hreq.Core.API.MediaType mediaEncode :: sing PlainText -> a -> ByteString Source # | |
ToJSON a => MediaEncode JSON a Source # | |
Defined in Hreq.Core.API.MediaType mediaEncode :: sing JSON -> a -> ByteString Source # |
class HasMediaType ctyp => MediaDecode ctyp a where Source #
mediaDecode :: sing ctyp -> ByteString -> Either DecodeError a Source #
Instances
FromForm a => MediaDecode FormUrlEncoded a Source # | |
Defined in Hreq.Core.API.MediaType mediaDecode :: sing FormUrlEncoded -> ByteString -> Either DecodeError a Source # | |
MediaDecode OctetStream ByteString Source # | |
Defined in Hreq.Core.API.MediaType mediaDecode :: sing OctetStream -> ByteString -> Either DecodeError ByteString Source # | |
MediaDecode OctetStream ByteString Source # | |
Defined in Hreq.Core.API.MediaType mediaDecode :: sing OctetStream -> ByteString0 -> Either DecodeError ByteString Source # | |
Read a => MediaDecode PlainText a Source # | |
Defined in Hreq.Core.API.MediaType mediaDecode :: sing PlainText -> ByteString -> Either DecodeError a Source # | |
MediaDecode PlainText Text Source # | |
Defined in Hreq.Core.API.MediaType mediaDecode :: sing PlainText -> ByteString -> Either DecodeError Text Source # | |
FromJSON a => MediaDecode JSON a Source # | |
Defined in Hreq.Core.API.MediaType mediaDecode :: sing JSON -> ByteString -> Either DecodeError a Source # |
class HasMediaType ctyp where Source #
Instances of HasMediaType
are useful for matching against the Accept
HTTP header
of the request and setting Content-Type
header of the response
Instances
HasMediaType FormUrlEncoded Source # | |
Defined in Hreq.Core.API.MediaType mediaType :: sing FormUrlEncoded -> MediaType Source # mediaTypes :: sing FormUrlEncoded -> NonEmpty MediaType Source # | |
HasMediaType OctetStream Source # | |
Defined in Hreq.Core.API.MediaType mediaType :: sing OctetStream -> MediaType Source # mediaTypes :: sing OctetStream -> NonEmpty MediaType Source # | |
HasMediaType PlainText Source # | |
HasMediaType JSON Source # | |
newtype DecodeError Source #
Instances
Eq DecodeError Source # | |
Defined in Hreq.Core.API.MediaType (==) :: DecodeError -> DecodeError -> Bool # (/=) :: DecodeError -> DecodeError -> Bool # | |
Show DecodeError Source # | |
Defined in Hreq.Core.API.MediaType showsPrec :: Int -> DecodeError -> ShowS # show :: DecodeError -> String # showList :: [DecodeError] -> ShowS # | |
Exception DecodeError Source # | |
Defined in Hreq.Core.API.MediaType |
data FormUrlEncoded Source #
Instances
HasMediaType FormUrlEncoded Source # | |
Defined in Hreq.Core.API.MediaType mediaType :: sing FormUrlEncoded -> MediaType Source # mediaTypes :: sing FormUrlEncoded -> NonEmpty MediaType Source # | |
ToForm a => MediaEncode FormUrlEncoded a Source # | |
Defined in Hreq.Core.API.MediaType mediaEncode :: sing FormUrlEncoded -> a -> ByteString Source # | |
FromForm a => MediaDecode FormUrlEncoded a Source # | |
Defined in Hreq.Core.API.MediaType mediaDecode :: sing FormUrlEncoded -> ByteString -> Either DecodeError a Source # |
data OctetStream Source #
Instances
HasMediaType OctetStream Source # | |
Defined in Hreq.Core.API.MediaType mediaType :: sing OctetStream -> MediaType Source # mediaTypes :: sing OctetStream -> NonEmpty MediaType Source # | |
MediaEncode OctetStream ByteString Source # | |
Defined in Hreq.Core.API.MediaType mediaEncode :: sing OctetStream -> ByteString -> ByteString Source # | |
MediaEncode OctetStream ByteString Source # | |
Defined in Hreq.Core.API.MediaType mediaEncode :: sing OctetStream -> ByteString -> ByteString0 Source # | |
MediaDecode OctetStream ByteString Source # | |
Defined in Hreq.Core.API.MediaType mediaDecode :: sing OctetStream -> ByteString -> Either DecodeError ByteString Source # | |
MediaDecode OctetStream ByteString Source # | |
Defined in Hreq.Core.API.MediaType mediaDecode :: sing OctetStream -> ByteString0 -> Either DecodeError ByteString Source # |
Instances
HasMediaType PlainText Source # | |
Show a => MediaEncode PlainText a Source # | |
Defined in Hreq.Core.API.MediaType mediaEncode :: sing PlainText -> a -> ByteString Source # | |
Read a => MediaDecode PlainText a Source # | |
Defined in Hreq.Core.API.MediaType mediaDecode :: sing PlainText -> ByteString -> Either DecodeError a Source # | |
MediaDecode PlainText Text Source # | |
Defined in Hreq.Core.API.MediaType mediaDecode :: sing PlainText -> ByteString -> Either DecodeError Text Source # |
Instances
HasMediaType JSON Source # | |
ToJSON a => MediaEncode JSON a Source # | |
Defined in Hreq.Core.API.MediaType mediaEncode :: sing JSON -> a -> ByteString Source # | |
FromJSON a => MediaDecode JSON a Source # | |
Defined in Hreq.Core.API.MediaType mediaDecode :: sing JSON -> ByteString -> Either DecodeError a Source # |
eitherDecodeLenient :: FromJSON a => ByteString -> Either String a Source #
Like eitherDecode
but allows all JSON values instead of just
objects and arrays. This function is borrowed from servant
Will handle trailing whitespace, but not trailing junk. ie.
>>>
eitherDecodeLenient "1 " :: Either String Int
Right 1
>>>
eitherDecodeLenient "1 junk" :: Either String Int
Left "trailing junk after valid JSON: endOfInput"
An HTTP media type, consisting of the type, subtype, and parameters.
Instances
Eq MediaType | |
Ord MediaType | |
Defined in Network.HTTP.Media.MediaType.Internal | |
Show MediaType | |
IsString MediaType | |
Defined in Network.HTTP.Media.MediaType.Internal fromString :: String -> MediaType # | |
RenderHeader MediaType | |
Defined in Network.HTTP.Media.MediaType.Internal renderHeader :: MediaType -> ByteString # | |
Accept MediaType | |
Defined in Network.HTTP.Media.MediaType.Internal parseAccept :: ByteString -> Maybe MediaType # matches :: MediaType -> MediaType -> Bool # moreSpecificThan :: MediaType -> MediaType -> Bool # |
(//) :: ByteString -> ByteString -> MediaType #
Builds a MediaType
without parameters. Can produce an error if
either type is invalid.
matches :: Accept a => a -> a -> Bool #
Evaluates whether either the left argument matches the right one.
This relation must be a total order, where more specific terms on the left can produce a match, but a less specific term on the left can never produce a match. For instance, when matching against media types it is important that if the client asks for a general type then we can choose a more specific offering from the server, but if a client asks for a specific type and the server only offers a more general form, then we cannot generalise. In this case, the server types will be the left argument, and the client types the right.
For types with no concept of specificity, this operation is just equality.
parseAccept :: Accept a => ByteString -> Maybe a #
Specifies how to parse an Accept-* header after quality has been handled.