Copyright | © 2017 Mark Karpov |
---|---|
License | BSD 3 clause |
Maintainer | Mark Karpov <markkarpov92@gmail.com> |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
This is modern library for working with URIs as per RFC 3986:
https://tools.ietf.org/html/rfc3986
This module is intended to be imported qualified, e.g.:
import Text.URI (URI) import qualified Text.URI as URI
See also Text.URI.Lens for lens, prisms, and traversals; see Text.URI.QQ for quasi-quoters for compile-time validation of URIs and refined text components.
- data URI = URI {}
- mkURI :: MonadThrow m => Text -> m URI
- makeAbsolute :: RText Scheme -> URI -> URI
- data Authority = Authority {}
- data UserInfo = UserInfo {
- uiUsername :: RText Username
- uiPassword :: Maybe (RText Password)
- data QueryParam
- = QueryFlag (RText QueryKey)
- | QueryParam (RText QueryKey) (RText QueryValue)
- data ParseException = ParseException Text (ParseError Char Void)
- data RText l
- data RTextLabel
- mkScheme :: MonadThrow m => Text -> m (RText Scheme)
- mkHost :: MonadThrow m => Text -> m (RText Host)
- mkUsername :: MonadThrow m => Text -> m (RText Username)
- mkPassword :: MonadThrow m => Text -> m (RText Password)
- mkPathPiece :: MonadThrow m => Text -> m (RText PathPiece)
- mkQueryKey :: MonadThrow m => Text -> m (RText QueryKey)
- mkQueryValue :: MonadThrow m => Text -> m (RText QueryValue)
- mkFragment :: MonadThrow m => Text -> m (RText Fragment)
- unRText :: RText l -> Text
- data RTextException = RTextException RTextLabel Text
- parser :: MonadParsec e Text m => m URI
- parserBs :: MonadParsec e ByteString m => m URI
- render :: URI -> Text
- render' :: URI -> Builder
- renderBs :: URI -> ByteString
- renderBs' :: URI -> Builder
- renderStr :: URI -> String
- renderStr' :: URI -> ShowS
Data types
Uniform resource identifier (URI) reference. We use refined Text
(
) here because information is presented in human-readable
form, i.e. percent-decoded, and thus it may contain Unicode characters.RText
l
mkURI :: MonadThrow m => Text -> m URI Source #
Construct a URI
from Text
. In case of failure ParseException
is
thrown.
This function uses the parser
parser under the hood, which you can also
use directly in a Megaparsec parser.
User info as a combination of username and password.
UserInfo | |
|
data QueryParam Source #
Query parameter either in the form of flag or as a pair of key and value. A key cannot be empty, while a value can.
QueryFlag (RText QueryKey) | Flag parameter |
QueryParam (RText QueryKey) (RText QueryValue) | Key–value pair |
data ParseException Source #
ParseException Text (ParseError Char Void) | Arguments are: original input and parse error |
Refined text
Refined text values can only be created by using the smart constructors
listed below, such as mkScheme
. This eliminates the possibility of
having an invalid component in URI
which could invalidate the whole
URI
.
Note that the refined text RText
type is labelled at the type level
with RTextLabel
s, which see.
When an invalid Text
value is passed to a smart constructor,
it rejects it by throwing the RTextException
. Remember that the Maybe
datatype is also an instance of MonadThrow
, and so
one could as well use the smart constructors in the Maybe
monad.
Refined text labelled at the type level.
Eq (RText l) Source # | |
Typeable RTextLabel l => Data (RText l) Source # | |
Ord (RText l) Source # | |
Show (RText l) Source # | |
Generic (RText l) Source # | |
Arbitrary (RText Scheme) Source # | |
Arbitrary (RText Host) Source # | |
Arbitrary (RText Username) Source # | |
Arbitrary (RText Password) Source # | |
Arbitrary (RText PathPiece) Source # | |
Arbitrary (RText QueryKey) Source # | |
Arbitrary (RText QueryValue) Source # | |
Arbitrary (RText Fragment) Source # | |
NFData (RText l) Source # | |
type Rep (RText l) Source # | |
data RTextLabel Source #
Refined text labels.
mkScheme :: MonadThrow m => Text -> m (RText Scheme) Source #
mkUsername :: MonadThrow m => Text -> m (RText Username) Source #
mkPassword :: MonadThrow m => Text -> m (RText Password) Source #
mkPathPiece :: MonadThrow m => Text -> m (RText PathPiece) Source #
mkQueryKey :: MonadThrow m => Text -> m (RText QueryKey) Source #
mkQueryValue :: MonadThrow m => Text -> m (RText QueryValue) Source #
Lift a Text
value into
.RText
QueryValue
This smart constructor does not perform any sort of normalization.
mkFragment :: MonadThrow m => Text -> m (RText Fragment) Source #
data RTextException Source #
The exception is thrown when a refined
value cannot be
constructed due to the fact that given RText
lText
value is not correct.
RTextException RTextLabel Text |
|
Parsing
parserBs :: MonadParsec e ByteString m => m URI Source #
This parser can be used to parse URI
from strict ByteString
.
Remember to use a concrete non-polymorphic parser type for efficiency.
Since: 0.0.2.0
Rendering
renderBs :: URI -> ByteString Source #
Render a given URI
value as a strict ByteString
.