hreq-core-0.1.0.0: Core functionality for Hreq Http client library

Safe HaskellNone
LanguageHaskell2010

Hreq.Core.API.MediaType

Description

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

Documentation

class HasMediaType ctyp => MediaEncode ctyp a where Source #

Methods

mediaEncode :: sing ctyp -> a -> ByteString Source #

Instances
ToForm a => MediaEncode FormUrlEncoded a Source # 
Instance details

Defined in Hreq.Core.API.MediaType

MediaEncode OctetStream ByteString Source # 
Instance details

Defined in Hreq.Core.API.MediaType

MediaEncode OctetStream ByteString Source # 
Instance details

Defined in Hreq.Core.API.MediaType

Show a => MediaEncode PlainText a Source # 
Instance details

Defined in Hreq.Core.API.MediaType

Methods

mediaEncode :: sing PlainText -> a -> ByteString Source #

ToJSON a => MediaEncode JSON a Source # 
Instance details

Defined in Hreq.Core.API.MediaType

Methods

mediaEncode :: sing JSON -> a -> ByteString 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

Minimal complete definition

mediaType | mediaTypes

Methods

mediaType :: sing ctyp -> MediaType Source #

mediaTypes :: sing ctyp -> NonEmpty MediaType Source #

data JSON Source #

Instances
HasMediaType JSON Source # 
Instance details

Defined in Hreq.Core.API.MediaType

ToJSON a => MediaEncode JSON a Source # 
Instance details

Defined in Hreq.Core.API.MediaType

Methods

mediaEncode :: sing JSON -> a -> ByteString Source #

FromJSON a => MediaDecode JSON a Source # 
Instance details

Defined in Hreq.Core.API.MediaType

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"

(//) :: 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.