1{-# LANGUAGE DefaultSignatures #-}
2module Web.HttpApiData (
7import Data.ByteString (ByteString)
9import Data.Text.Encoding (encodeUtf8, decodeUtf8)
11-- | Convert value to HTTP API data.
12class ToHttpApiData a where
13 -- | Convert to URL path piece.
14 toUrlPiece :: a -> Text
15 toUrlPiece = toQueryParam
17 -- | Convert to HTTP header value.
18 toHeader :: a -> ByteString
19 toHeader = encodeUtf8 . toUrlPiece
21 -- | Convert to query param value.
22 toQueryParam :: a -> Text
23 toQueryParam = toUrlPiece
25-- | Convert value from HTTP API data.
26class FromHttpApiData a where
27 -- | Parse URL path piece.
28 parseUrlPiece :: Text -> Either Text a
29 parseUrlPiece = parseQueryParam
31 -- | Parse HTTP header value.
32 parseHeader :: ByteString -> Either Text a
33 parseHeader = parseUrlPiece . decodeUtf8
35 -- | Parse query param value.
36 parseQueryParam :: Text -> Either Text a
37 parseQueryParam = parseUrlPiece
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list