HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleuri-bytestring-0.4.0.0Haskell2010

URI.ByteString

URI.ByteString aims to be an RFC3986 compliant URI parser that uses efficient ByteStrings for parsing and representing the data. This module provides a URI datatype as well as a parser and serializer.

Note that this library is an early release and may have issues. It is currently being used in production and no issues have been encountered, however. Please report any issues encountered to the issue tracker.

This module also provides analogs to Lens over the various types in this library. These are written in a generic way to avoid a dependency on any particular lens library. You should be able to use these with a number of packages including lens and lens-family-core.

  • 15 types
  • 54 values

URI-related types

20 declarations
newtypenewtype Scheme
#

Required first component to referring to a specification for the remainder of the URI's components, e.g. "http" or "https"

Constructors

Instances6Eq, Ord, Show, Generic, Lift, Rep
newtypenewtype Host
#

Constructors

Instances6Eq, Ord, Show, Generic, Lift, Rep
newtypenewtype Port
#

While some libraries have chosen to limit this to a Word16, the spec only specifies that the string be comprised of digits.

Constructors

Instances6Eq, Ord, Show, Generic, Lift, Rep
datadata Authority
#
Instances6Eq, Ord, Show, Generic, Lift, Rep
datadata UserInfo
#
Instances6Eq, Ord, Show, Generic, Lift, Rep
newtypenewtype Query
#
Instances8Eq, Ord, Show, Generic, Semigroup, Monoid, …
datadata URIRef a where
#
Instances4Lift, Eq, Ord, Show
  • Lift (URIRef a)Defined in uri-bytestring-0.4.0.0 · URI.ByteString.Types
  • Eq (URIRef a)Defined in uri-bytestring-0.4.0.0 · URI.ByteString.Types
  • Ord (URIRef a)Defined in uri-bytestring-0.4.0.0 · URI.ByteString.Types
  • Show (URIRef a)Defined in uri-bytestring-0.4.0.0 · URI.ByteString.Types
datadata Absolute
#
Instances1Lift
  • Lift AbsoluteDefined in uri-bytestring-0.4.0.0 · URI.ByteString.Types
datadata Relative
#
Instances1Lift
  • Lift RelativeDefined in uri-bytestring-0.4.0.0 · URI.ByteString.Types
datadata SchemaError
#

URI Parser Types

Constructors

Instances7Bounded, Enum, Eq, Read, Show, Generic, …
datadata URIParseError
#
Instances5Eq, Read, Show, Generic, Rep

Strict URI Parser config. Follows RFC3986 as-specified. Use this if you can be certain that your URIs are properly encoded or if you want parsing to fail if they deviate from the spec at all.

Lax URI Parser config. Use this if you you want to handle common deviations from the spec gracefully.

  • Allows non-encoded [ and ] in query string

Constructors

Instances2Eq, Show

Operations

1 declaration

Parsing

4 declarations

Parse a strict ByteString into a URI or an error.

Example:

Example1 expression
parseURI strictURIParserOptions "http://www.example.org/foo?bar=baz#quux"Right (URI {uriScheme = Scheme {schemeBS = "http"}, uriAuthority = Just (Authority {authorityUserInfo = Nothing, authorityHost = Host {hostBS = "www.example.org"}, authorityPort = Nothing}), uriPath = "/foo", uriQuery = Query {queryPairs = [("bar","baz")]}, uriFragment = Just "quux"})
Example1 expression
parseURI strictURIParserOptions "$$$$://badurl.example.org"Left (MalformedScheme NonAlphaLeading)

There are some urls that you'll encounter which defy the spec, such as those with square brackets in the query string. If you must be able to parse those, you can use "laxURIParserOptions" or specify your own

Example1 expression
parseURI strictURIParserOptions "http://www.example.org/foo?bar[]=baz"Left MalformedQuery
Example1 expression
parseURI laxURIParserOptions "http://www.example.org/foo?bar[]=baz"Right (URI {uriScheme = Scheme {schemeBS = "http"}, uriAuthority = Just (Authority {authorityUserInfo = Nothing, authorityHost = Host {hostBS = "www.example.org"}, authorityPort = Nothing}), uriPath = "/foo", uriQuery = Query {queryPairs = [("bar[]","baz")]}, uriFragment = Nothing})
Example2 expressions
let myLaxOptions = URIParserOptions { upoValidQueryChar = liftA2 (||) (upoValidQueryChar strictURIParserOptions) (inClass "[]")}parseURI myLaxOptions "http://www.example.org/foo?bar[]=baz"Right (URI {uriScheme = Scheme {schemeBS = "http"}, uriAuthority = Just (Authority {authorityUserInfo = Nothing, authorityHost = Host {hostBS = "www.example.org"}, authorityPort = Nothing}), uriPath = "/foo", uriQuery = Query {queryPairs = [("bar[]","baz")]}, uriFragment = Nothing})

Serializing

10 declarations
valueserializeURIRef :: URIRef a -> Builder
#

URI Serializer

Serialize a URI reference into a Builder.

Example of serializing + converting to a lazy Data.ByteString.Lazy.ByteString:

Example1 expression
BB.toLazyByteString $ serializeURIRef $ URI {uriScheme = Scheme {schemeBS = "http"}, uriAuthority = Just (Authority {authorityUserInfo = Nothing, authorityHost = Host {hostBS = "www.example.org"}, authorityPort = Nothing}), uriPath = "/foo", uriQuery = Query {queryPairs = [("bar","baz")]}, uriFragment = Just "quux"}"http://www.example.org/foo?bar=baz#quux"

Normalized Serialization

Low level utility functions

3 declarations

Lenses

0 declarations

Lenses over Scheme

Lenses over Host

Lenses over Port

Lenses over Authority

Lenses over UserInfo

Lenses over Query

Lenses over URIRef

Lenses over URIParserOptions

Deprecated