HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Moduleuri-bytestring-0.4.0.1Haskell2010

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.

Contents
  1. URI-related types
  2. Operations
  3. Parsing
  4. Serializing
  5. Normalized Serialization
  6. Low level utility functions
  7. Lenses
  8. Lenses over Scheme
  9. Lenses over Host
  10. Lenses over Port
  11. Lenses over Authority
  12. Lenses over UserInfo
  13. Lenses over Query
  14. Lenses over URIRef
  15. Lenses over URIParserOptions
  16. Deprecated
Synopsis

URI-related types

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.1 · URI.ByteString.Types
  • Eq (URIRef a)Defined in uri-bytestring-0.4.0.1 · URI.ByteString.Types
  • Ord (URIRef a)Defined in uri-bytestring-0.4.0.1 · URI.ByteString.Types
  • Show (URIRef a)Defined in uri-bytestring-0.4.0.1 · URI.ByteString.Types
datadata Absolute
#
Instances1Lift
  • Lift AbsoluteDefined in uri-bytestring-0.4.0.1 · URI.ByteString.Types
datadata Relative
#
Instances1Lift
  • Lift RelativeDefined in uri-bytestring-0.4.0.1 · 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.

Constructors

Instances2Eq, Show

Operations

Parsing

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

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

Lenses

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