Skip to content

Commit

Permalink
Add toEncodedUrlPiece
Browse files Browse the repository at this point in the history
  • Loading branch information
edsko committed Feb 7, 2017
1 parent f55c9db commit a10979b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions http-api-data.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ library
, bytestring
, containers
, hashable
, http-types
, text >= 0.5
, time
, time-locale-compat >=0.1.1.0 && <0.2
Expand Down
7 changes: 7 additions & 0 deletions src/Web/Internal/HttpApiData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ import qualified Data.UUID.Types as UUID

import Data.Typeable (Typeable)
import Data.Data (Data)
import qualified Data.ByteString.Builder as BS
import qualified Network.HTTP.Types as H


-- $setup
-- >>> data BasicAuthToken = BasicAuthToken Text deriving (Show)
Expand All @@ -70,6 +73,10 @@ class ToHttpApiData a where
toUrlPiece :: a -> Text
toUrlPiece = toQueryParam

-- | Convert to a URL path piece, making sure to encode any special chars
toEncodedUrlPiece :: a -> BS.Builder
toEncodedUrlPiece = H.encodePathSegmentsRelative . (:[]) . toUrlPiece

-- | Convert to HTTP header value.
toHeader :: a -> ByteString
toHeader = encodeUtf8 . toUrlPiece
Expand Down

0 comments on commit a10979b

Please sign in to comment.