MyNixOS website logo
Description

Library for type-safe representations of Uri/Urls.

Dormouse-Uri provides type safe handling of Uris and Urls.

Uri sytax is well defined according to RFC 3986, Dormouse-Uri parses and encodes Uris according to the syntax defined in this document.

We define Url as an absolute URI associated with web resources, the current version of Dormouse-Uri restricts Urls to the http and https schemes.

Dormouse-Uri has the following features:

  • The Uri and Url data types use Data.Text internally, this allows you to freely include percent-decoded characters which will be properly rendered when the Url/Uri is encoded.

  • Quasiquoters to allow safe construction of Uri/Urls from string literals.

  • DataKinds allow Urls to be restricted to the http or https schemes are the type level.

  • A UrlBuilder syntax to allow type-safe construction/concatenation of Urls from their components, e.g. path and query parameters.

Please see https://dormouse.io for full documentation.

Dormouse-Uri

Dormouse-Uri provides type safe handling of Uris and Urls.

Uri sytax is well defined according to RFC 3986, Dormouse-Uri parses and encodes Uris according to the syntax defined in this document.

We define Url as an absolute URI associated with web resources, the current version of Dormouse-Uri restricts Urls to the http and https schemes.

Dormouse-Uri has the following features:

  • The Uri/Url data types use Data.Text internally, this allows you to freely include percent-decoded characters which will be properly rendered when the Url/Uri is encoded.
  • Quasiquoters to allow safe construction of Uri/Urls from string literals.
  • DataKinds allow Urls to be restricted to the http or https schemes are the type level.
  • A UrlBuilder syntax to allow type-safe construction/concatenation of Urls from their components, e.g. path and query parameters.

Constructing Uris

{-# LANGUAGE QuasiQuotes #-}

import Dormouse.Uri
import Dormouse.Uri.QQ

telUri :: Uri
telUri = [uri|tel:+1-816-555-1212|]

mailtoUri :: Uri
mailtoUri = [uri|mailto:[email protected]|]

httpUri :: Uri
httpUri = [uri|http://haskell.org|]

Constructing Urls

You can construct Urls using the helper QuasiQuoters:

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE QuasiQuotes #-}

import Dormouse.Url
import Dormouse.Url.QQ

githubHttpsUrl :: Url "https"
githubHttpsUrl = [https|https://github.com|]

githubHttpUrl :: Url "http"
githubHttpUrl = [http|http://github.com|]

githubAnyUrl :: AnyUrl
githubAnyUrl = [url|http://github.com|]

You can use the Url Builder syntax to modify an existing Url safely to include paths, adding the import:

import Dormouse.Url.Builder

To allow:

dormouseHttpsUrl :: Url "https"
dormouseHttpsUrl = githubHttpsUrl </> "TheInnerLight" </> "dormouse"

The Url will be constructed safely so that any characters that wouldn't normally be allowed in a Url path are percent-encoded before the url is resolved by Dormouse.

You can also handle query parameters using similar syntax:

searchUrl :: Url "https"
searchUrl = [https|https://google.com|] </> "search" ? "q" =: ("haskell" :: String)
Metadata

Version

0.2.0.0

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows