Safe Haskell | None |
---|---|
Language | Haskell2010 |
Servant.API.ResponseHeaders
Description
This module provides facilities for adding headers to a response.
>>>
let headerVal = addHeader "some-url" 5 :: Headers '[Header "Location" String] Int
The value is added to the header specified by the type (
Location
in the
example above).
Synopsis
-
data
Headers
ls a =
Headers
{
- getResponse :: a
- getHeadersHList :: HList ls
- data ResponseHeader (sym :: Symbol ) a
- class AddHeader h v orig new | h v orig -> new, new -> h, new -> v, new -> orig
- addHeader :: AddHeader h v orig new => v -> orig -> new
- noHeader :: AddHeader h v orig new => orig -> new
- class HasResponseHeader h a headers
- lookupResponseHeader :: HasResponseHeader h a headers => Headers headers r -> ResponseHeader h a
-
class
BuildHeadersTo
hs
where
- buildHeadersTo :: [ Header ] -> HList hs
-
class
GetHeaders
ls
where
- getHeaders :: ls -> [ Header ]
- class GetHeaders' hs
- type family HeaderValMap (f :: * -> *) (xs :: [*]) where ...
- data HList a where
Documentation
Response Header objects. You should never need to construct one directly.
Instead, use
addOptionalHeader
.
Constructors
Headers | |
Fields
|
Instances
( KnownSymbol h, ToHttpApiData v) => AddHeader h v ( Headers (fst ': rest) a) ( Headers ( Header h v ': (fst ': rest)) a) Source # | |
Defined in Servant.API.ResponseHeaders Methods addOptionalHeader :: ResponseHeader h v -> Headers (fst ': rest) a -> Headers ( Header h v ': (fst ': rest)) a |
|
Functor ( Headers ls) Source # | |
(NFDataHList ls, NFData a) => NFData ( Headers ls a) Source # | |
Defined in Servant.API.ResponseHeaders |
|
GetHeaders' hs => GetHeaders ( Headers hs a) Source # | |
Defined in Servant.API.ResponseHeaders Methods getHeaders :: Headers hs a -> [ Header ] Source # |
data ResponseHeader (sym :: Symbol ) a Source #
Constructors
Header a | |
MissingHeader | |
UndecodableHeader ByteString |
Instances
Functor ( ResponseHeader sym) Source # | |
Defined in Servant.API.ResponseHeaders Methods fmap :: (a -> b) -> ResponseHeader sym a -> ResponseHeader sym b Source # (<$) :: a -> ResponseHeader sym b -> ResponseHeader sym a Source # |
|
Eq a => Eq ( ResponseHeader sym a) Source # | |
Defined in Servant.API.ResponseHeaders Methods (==) :: ResponseHeader sym a -> ResponseHeader sym a -> Bool Source # (/=) :: ResponseHeader sym a -> ResponseHeader sym a -> Bool Source # |
|
Show a => Show ( ResponseHeader sym a) Source # | |
Defined in Servant.API.ResponseHeaders |
|
NFData a => NFData ( ResponseHeader sym a) Source # | |
Defined in Servant.API.ResponseHeaders Methods rnf :: ResponseHeader sym a -> () Source # |
class AddHeader h v orig new | h v orig -> new, new -> h, new -> v, new -> orig Source #
Minimal complete definition
addOptionalHeader
Instances
( KnownSymbol h, ToHttpApiData v, new ~ Headers '[ Header h v] a) => AddHeader h v a new Source # | |
Defined in Servant.API.ResponseHeaders Methods addOptionalHeader :: ResponseHeader h v -> a -> new |
|
( KnownSymbol h, ToHttpApiData v) => AddHeader h v ( Headers (fst ': rest) a) ( Headers ( Header h v ': (fst ': rest)) a) Source # | |
Defined in Servant.API.ResponseHeaders Methods addOptionalHeader :: ResponseHeader h v -> Headers (fst ': rest) a -> Headers ( Header h v ': (fst ': rest)) a |
addHeader :: AddHeader h v orig new => v -> orig -> new Source #
addHeader
adds a header to a response. Note that it changes the type of
the value in the following ways:
- A simple value is wrapped in "Headers '[hdr]":
>>>
let example1 = addHeader 5 "hi" :: Headers '[Header "someheader" Int] String;
>>>
getHeaders example1
[("someheader","5")]
- A value that already has a header has its new header *prepended* to the existing list:
>>>
let example1 = addHeader 5 "hi" :: Headers '[Header "someheader" Int] String;
>>>
let example2 = addHeader True example1 :: Headers '[Header "1st" Bool, Header "someheader" Int] String
>>>
getHeaders example2
[("1st","true"),("someheader","5")]
Note that while in your handlers type annotations are not required, since the type can be inferred from the API type, in other cases you may find yourself needing to add annotations.
noHeader :: AddHeader h v orig new => orig -> new Source #
Deliberately do not add a header to a value.
>>>
let example1 = noHeader "hi" :: Headers '[Header "someheader" Int] String
>>>
getHeaders example1
[]
class HasResponseHeader h a headers Source #
Minimal complete definition
hlistLookupHeader
Instances
HasResponseHeader h a rest => HasResponseHeader h a (first ': rest) Source # | |
Defined in Servant.API.ResponseHeaders Methods hlistLookupHeader :: HList (first ': rest) -> ResponseHeader h a |
|
HasResponseHeader h a ( Header h a ': rest) Source # | |
Defined in Servant.API.ResponseHeaders Methods hlistLookupHeader :: HList ( Header h a ': rest) -> ResponseHeader h a |
lookupResponseHeader :: HasResponseHeader h a headers => Headers headers r -> ResponseHeader h a Source #
Look up a specific ResponseHeader, without having to know what position it is in the HList.
>>>
let example1 = addHeader 5 "hi" :: Headers '[Header "someheader" Int] String
>>>
let example2 = addHeader True example1 :: Headers '[Header "1st" Bool, Header "someheader" Int] String
>>>
lookupResponseHeader example2 :: ResponseHeader "someheader" Int
Header 5
>>>
lookupResponseHeader example2 :: ResponseHeader "1st" Bool
Header True
Usage of this function relies on an explicit type annotation of the header to be looked up. This can be done with type annotations on the result, or with an explicit type application. In this example, the type of header value is determined by the type-inference, we only specify the name of the header:
>>>
:set -XTypeApplications
>>>
case lookupResponseHeader @"1st" example2 of { Header b -> b ; _ -> False }
True
Since: 0.15
class BuildHeadersTo hs where Source #
Methods
buildHeadersTo :: [ Header ] -> HList hs Source #
Note: if there are multiple occurrences of a header in the argument, the values are interspersed with commas before deserialization (see RFC2616 Sec 4.2 )
Instances
BuildHeadersTo ('[] :: [ Type ]) Source # | |
Defined in Servant.API.ResponseHeaders Methods buildHeadersTo :: [ Header ] -> HList '[] Source # |
|
( FromHttpApiData v, BuildHeadersTo xs, KnownSymbol h) => BuildHeadersTo ( Header h v ': xs) Source # | |
Defined in Servant.API.ResponseHeaders |
class GetHeaders ls where Source #
Methods
getHeaders :: ls -> [ Header ] Source #
Instances
GetHeadersFromHList hs => GetHeaders ( HList hs) Source # | |
Defined in Servant.API.ResponseHeaders Methods getHeaders :: HList hs -> [ Header ] Source # |
|
GetHeaders' hs => GetHeaders ( Headers hs a) Source # | |
Defined in Servant.API.ResponseHeaders Methods getHeaders :: Headers hs a -> [ Header ] Source # |
class GetHeaders' hs Source #
Auxiliary class for
instance
GetHeaders
(
Headers
hs a)
Minimal complete definition
getHeaders'
Instances
GetHeaders' ('[] :: [ Type ]) Source # |
This instance is an optimisation |
Defined in Servant.API.ResponseHeaders Methods getHeaders' :: Headers '[] a -> [ Header ] |
|
( KnownSymbol h, GetHeadersFromHList rest, ToHttpApiData v) => GetHeaders' ( Header h v ': rest) Source # | |
Defined in Servant.API.ResponseHeaders Methods getHeaders' :: Headers ( Header h v ': rest) a -> [ Header0 ] |
type family HeaderValMap (f :: * -> *) (xs :: [*]) where ... Source #
Equations
HeaderValMap f '[] = '[] | |
HeaderValMap f ( Header h x ': xs) = Header h (f x) ': HeaderValMap f xs |
Instances
NFDataHList xs => NFData ( HList xs) Source # | |
Defined in Servant.API.ResponseHeaders |
|
GetHeadersFromHList hs => GetHeaders ( HList hs) Source # | |
Defined in Servant.API.ResponseHeaders Methods getHeaders :: HList hs -> [ Header ] Source # |