git.iko.soy/typeable/http-api-data
on master help sign in
Add toEncodedUrlPiece
commita10979ba74ea5b9aed29091985f6d4ac6227e182 authorEdsko de Vries <edsko@well-typed.com> dateTue 7 Feb 2017, 16:50 (10 years ago) parentf55c9db
2 files changed+8
http-api-data.cabal+1 src/Web/Internal/HttpApiData.hs+7
http-api-data.cabal+1
@@ -41,6 +41,7 @@ library
4141 , bytestring
4242 , containers
4343 , hashable
44+ , http-types
4445 , text >= 0.5
4546 , time
4647 , time-locale-compat >=0.1.1.0 && <0.2
src/Web/Internal/HttpApiData.hs+7
@@ -55,6 +55,9 @@ import qualified Data.UUID.Types as UUID
5555
5656import Data.Typeable (Typeable)
5757import Data.Data (Data)
58+import qualified Data.ByteString.Builder as BS
59+import qualified Network.HTTP.Types as H
60+
5861
5962-- $setup
6063-- >>> data BasicAuthToken = BasicAuthToken Text deriving (Show)
@@ -70,6 +73,10 @@ class ToHttpApiData a where
7073 toUrlPiece :: a -> Text
7174 toUrlPiece = toQueryParam
7275
76+ -- | Convert to a URL path piece, making sure to encode any special chars
77+ toEncodedUrlPiece :: a -> BS.Builder
78+ toEncodedUrlPiece = H.encodePathSegmentsRelative . (:[]) . toUrlPiece
79+
7380 -- | Convert to HTTP header value.
7481 toHeader :: a -> ByteString
7582 toHeader = encodeUtf8 . toUrlPiece