urlpath: Painfully simple URL writing combinators

[ bsd3, data, library, web ] [ Propose Tags ]
This version is deprecated.

Simple URL DSL for Haskell.

This library tries to make it easier for people to write Url strings, structurally. Packages like Yesod Routes do a wonderful job at implementing string-free routing and references, but sometimes we have to compromise. This tries to make that compromise less painful.

Use bare combinators to render your strings (kinda useless):

 expandRelative $ "foo.php" <?> ("key1","bar") <&> ("key2","baz")

 ↪ "foo.php?key1=bar&key2=baz"

... or use the MonadReader instance for a configurable host:

 let path = runAbsoluteUrlT $ queryUrl $ "foo.php" <?> ("key1","bar") <&> ("key2","baz")
 path "example.com"

 ↪ "example.com/foo.php?key1=bar&key2=baz"

url puts the UrlString in a MonadReader that we can use for applying our host. We use different monads for different deployment schemes (currently we have 3 - RelativeUrl, GroundedUrl, and AbsoluteUrl), which we can integrate in different libraries, like Lucid:

 (runAbsoluteUrlT $ renderTextT $ do
     foo <- lift $ queryUrl $ "foo" <?> ("bar","baz")
     script_ [src_ foo] "" )
 ) "example.com"

 ↪ "<script src=\"example.com/foo?bar=baz\"></script>"

... and in Scotty ...

 main :: IO ()
 main = scottyT 3000
     rootConf
     rootConf
     run

   where
     rootConf = flip runAbsoluteUrlT "http://example.com"

     run :: ( MonadIO m
            , MonadReader T.Text m
            , Url T.Text m ) =>
            ScottyT LT.Text m ()
     run = get "/" $ do
       path <- lift $ queryUrl $ "foo" <?> ("bar","baz")
       text $ LT.fromStrict path

 λ> curl localhost:3000/
 ↪ "http://example.com/foo?bar=baz"

Note that in the scotty example, we don't use one of our deployment schemes - this is because the scottyT function expects it's underlying monad to be an instance of MonadIO, which we can only instantiate in our monad transformers.

Please take mind - the string type underlying the Url rendering is generalized to Data.String.IsString for convenient use with -XOverloadedStrings. However, due to that generality, we need to specify the monomorphic type (like Data.Text.Text above).

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

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.0.1, 0.0.2, 0.0.3, 0.0.4, 0.0.5, 0.0.6, 0.1, 0.1.0.1, 0.2, 1.0.0, 1.1.0, 2.0.0, 2.1.0, 3.0.0, 3.1.0, 3.1.1, 3.2.0, 3.2.1, 3.2.1.1, 3.3.0, 4.0.0, 4.0.0.1, 4.1.0, 4.2.0, 5.0.0, 5.0.0.1, 6.0.0, 6.0.1, 6.0.2, 6.0.3, 6.0.4, 7.0.0, 7.0.1, 7.0.2, 7.1.0, 8.0.0, 8.0.1, 8.1.0, 8.2.0, 9.0.0, 9.0.0.1, 9.0.1, 10.0.0, 11.0.0, 11.0.1, 11.0.2 (info)
Dependencies base (>=4 && <5), monoid-subclasses, mtl, transformers [details]
License MIT
Author Athan Clark <athan.clark@gmail.com>
Maintainer Athan Clark <athan.clark@gmail.com>
Revised Revision 1 made by athanclark at 2015-05-27T20:10:29Z
Category Web, Data
Source repo head: git clone https://github.com/athanclark/urlpath.git
Uploaded by athanclark at 2015-05-13T23:39:08Z
Distributions LTSHaskell:11.0.2, Stackage:11.0.2
Reverse Dependencies 4 direct, 1 indirect [details]
Downloads 20769 total (117 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]