1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE Trustworthy, FlexibleInstances, UnicodeSyntax #-}
-- | This module exports all the things at the same time, plus a utility
-- function.
module Network.HTTP.Link (
module Network.HTTP.Link.Types
, module Network.HTTP.Link.Writer
, module Network.HTTP.Link.Parser
, lnk
) where
import Control.Error.Util (hush)
import Data.Text (Text, pack)
import Data.Text.Encoding
import safe Network.HTTP.Link.Parser
import safe Network.HTTP.Link.Types
import safe Network.HTTP.Link.Writer
import Web.HttpApiData
instance (IsURI uri) ⇒ ToHttpApiData [Link uri] where
toUrlPiece = toUrlPiece . writeLinkHeader
toHeader = encodeUtf8 . writeLinkHeader
instance (IsURI uri) ⇒ ToHttpApiData (Link uri) where
toUrlPiece = toUrlPiece . writeLink
toHeader = encodeUtf8 . writeLink
-- | Construct a Link.
lnk ∷ (IsURI uri) ⇒ String → [(LinkParam, Text)] → Maybe (Link uri)
lnk u r = fmap (\x → Link x r) $ hush $ uriFromText $ pack u
|