modern-uri: Modern library for working with URIs

[ bsd3, library, text ] [ Propose Tags ]

Modern library for working with URIs.


[Skip to Readme]
Versions [faq] 0.0.1.0, 0.0.2.0, 0.1.0.0, 0.1.1.0, 0.1.1.1, 0.1.2.0, 0.1.2.1, 0.2.0.0, 0.2.1.0, 0.2.2.0, 0.3.0.0, 0.3.0.1
Change log CHANGELOG.md
Dependencies base (>=4.7 && <5.0), bytestring (>=0.2 && <0.11), containers (==0.5.*), contravariant (>=1.3 && <2.0), deepseq (>=1.3 && <1.5), exceptions (>=0.6 && <0.9), megaparsec (>=6.0 && <6.4), profunctors (>=5.2.1 && <6.0), QuickCheck (>=2.4 && <3.0), semigroups (==0.18.*), template-haskell (>=2.10 && <2.13), text (>=0.2 && <1.3) [details]
License BSD-3-Clause
Author Mark Karpov <markkarpov92@gmail.com>
Maintainer Mark Karpov <markkarpov92@gmail.com>
Revised Revision 1 made by mrkkrp at Sun Dec 31 09:23:29 UTC 2017
Category Text
Home page https://github.com/mrkkrp/modern-uri
Bug tracker https://github.com/mrkkrp/modern-uri/issues
Source repo head: git clone https://github.com/mrkkrp/modern-uri.git
Uploaded by mrkkrp at Sun Oct 29 11:05:40 UTC 2017
Distributions LTSHaskell:0.3.0.1, NixOS:0.3.0.1, Stackage:0.3.0.1
Downloads 2930 total (57 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2017-10-29 [all 1 reports]

Modules

[Index]

Flags

NameDescriptionDefaultType
dev

Turn on development settings.

DisabledManual

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

For package maintainers and hackage trustees


Readme for modern-uri-0.0.2.0

[back to package description]

Modern URI

License BSD3 Hackage Stackage Nightly Stackage LTS Build Status Coverage Status

This is a modern library for working with URIs in Haskell as per RFC 3986:

https://tools.ietf.org/html/rfc3986

Motivation

There are already at least three libraries for working with URIs: uri, network-uri, and uri-bytestring. Why write one more?

Let's see first about the uri and network-uri packages (they are quite similar):

  • They use String instead of Text or ByteString, this is inefficient.
  • The types are not very precise. Query string is represented as Maybe String for example.
  • The packages use Parsec under the hood, however they do not allow us to use its URI parser in a bigger Parsec parser.

Now what about uri-bytestring?

  • Works with ByteString, which totally makes sense because a URI can have only ASCII characters in it. However sometimes a URI is a part of a bigger document that can contain Unicode characters and so we may need to parse a URI from Text or render it to Text. Ideally, we would like to be able to parse from both Text and ByteString as well to render to both Text and ByteString.
  • Does not allow to use its URI parser as part of a bigger parser.
  • Provides newtype wrappers for different components of URI, but we could still put something incorrect inside.
  • Absolute and relative URI references have different types, which may or may not be handy.
  • Provides lenses, but does not provide e.g. traversal for working with query parameters selected by their names.

Features

The modern-uri package features:

  • Correct by construction URI data type. Correctness is ensured by guaranteeing that every sub-component of the URI record is by itself cannot be invalid. This boils down to careful use of types and a set of smart constructors for things like scheme, host, etc.
  • Textual components in the URI data type represented as Text rather than ByteString, because they are percent-decoded and so they can contain characters outside of ASCII range (i.e. Unicode). This allows for easier manipulation of URIs, while encoding and decoding headaches are handled by the parsers and renders for you.
  • Absolute and relative URIs differ only by the scheme component: if it's Nothing, then URI is relative, otherwise it's absolute.
  • Megaparsec parser that can be used as a standalone smart constructor for the URI data type (see mkURI) as well as be seamlessly integrated into a bigger Megaparsec parser that consumes strict Text (see parser) or strict ByteString (see parserBs).
  • The parser performs some normalization, for example it collapses consecutive slashes. Some smart constructors such as mkScheme and mkHost also perform normalization. So in a sense URIs are also “normalized by construction” to some extent.
  • Fast rendering to strict Text and ByteString as well as to their respective Builder types and to String/ShowS.
  • Extensive set of lensy helpers for easier manipulation of the nested data types (see Text.URI.Lens).
  • Quasi-quoters for compile-time construction of the URI data type and refined text types (see Text.URI.QQ).

Contribution

Issues, bugs, and questions may be reported in the GitHub issue tracker for this project.

Pull requests are also welcome and will be reviewed quickly.

License

Copyright © 2017 Mark Karpov

Distributed under BSD 3 clause license.