File: Link.hs

package info (click to toggle)
haskell-http-link-header 1.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 112 kB
  • sloc: haskell: 309; makefile: 8
file content (31 lines) | stat: -rw-r--r-- 1,045 bytes parent folder | download | duplicates (2)
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