web-routes-0.27.14: portable, type-safe URL routing

Safe HaskellNone
LanguageHaskell98

Web.Routes.PathInfo

Contents

Synopsis

Documentation

stripOverlap :: Eq a => [a] -> [a] -> [a] Source #

pToken :: tok -> (Text -> Maybe a) -> URLParser a Source #

segment :: Text -> URLParser Text Source #

match on a specific string

anySegment :: URLParser Text Source #

match on any string

patternParse :: ([Text] -> Either String a) -> URLParser a Source #

apply a function to the remainder of the segments

useful if you want to just do normal pattern matching: > > foo ["foo", "bar"] = Right (Foo Bar) > foo ["baz"] = Right Baz > foo _ = Left "parse error"

patternParse foo

parseSegments :: URLParser a -> [Text] -> Either String a Source #

run a URLParser on a list of path segments

returns Left "parse error" on failure.

returns Right a on success

class PathInfo url where Source #

Simple parsing and rendering for a type to and from URL path segments.

If you're using GHC 7.2 or later, you can use DeriveGeneric to derive instances of this class:

{-# LANGUAGE DeriveGeneric #-}
data Sitemap = Home | BlogPost Int deriving Generic
instance PathInfo Sitemap

This results in the following instance:

instance PathInfo Sitemap where
    toPathSegments Home = ["home"]
    toPathSegments (BlogPost x) = "blog-post" : toPathSegments x
    fromPathSegments = Home <$ segment "home"
                   <|> BlogPost <$ segment "blog-post" <*> fromPathSegments

And here it is in action:

>>> toPathInfo (BlogPost 123)
"/blog-post/123"
>>> fromPathInfo "/blog-post/123" :: Either String Sitemap
Right (BlogPost 123)

To instead derive instances using TemplateHaskell, see web-routes-th.

Methods

toPathSegments :: url -> [Text] Source #

fromPathSegments :: URLParser url Source #

toPathSegments :: (Generic url, GPathInfo (Rep url)) => url -> [Text] Source #

fromPathSegments :: (Generic url, GPathInfo (Rep url)) => URLParser url Source #

toPathInfo :: PathInfo url => url -> Text Source #

convert url into the path info portion of a URL

toPathInfoParams Source #

Arguments

:: PathInfo url 
=> url

url

-> [(Text, Maybe Text)]

query string parameter

-> Text 

convert url + params into the path info portion of a URL + a query string

fromPathInfo :: PathInfo url => ByteString -> Either String url Source #

parse a String into url using PathInfo.

returns Left "parse error" on failure

returns Right url on success

fromPathInfoParams :: PathInfo url => ByteString -> Either String (url, [(Text, Maybe Text)]) Source #

parse a String into '(url, Query)' using PathInfo.

returns Left "parse error" on failure

returns Right (url, Query on success

mkSitePI Source #

Arguments

:: PathInfo url 
=> ((url -> [(Text, Maybe Text)] -> Text) -> url -> a)

a routing function

-> Site url a 

turn a routing function into a Site value using the PathInfo class

showParseError :: ParseError -> String Source #

show Parsec ParseError using terms that relevant to parsing a url

Re-exported for convenience

class Generic a #

Representable types of kind *. This class is derivable in GHC with the DeriveGeneric flag on.

Minimal complete definition

from, to

Instances

Generic Bool 

Associated Types

type Rep Bool :: * -> * #

Methods

from :: Bool -> Rep Bool x #

to :: Rep Bool x -> Bool #

Generic Ordering 

Associated Types

type Rep Ordering :: * -> * #

Methods

from :: Ordering -> Rep Ordering x #

to :: Rep Ordering x -> Ordering #

Generic Exp 

Associated Types

type Rep Exp :: * -> * #

Methods

from :: Exp -> Rep Exp x #

to :: Rep Exp x -> Exp #

Generic Match 

Associated Types

type Rep Match :: * -> * #

Methods

from :: Match -> Rep Match x #

to :: Rep Match x -> Match #

Generic Clause 

Associated Types

type Rep Clause :: * -> * #

Methods

from :: Clause -> Rep Clause x #

to :: Rep Clause x -> Clause #

Generic Pat 

Associated Types

type Rep Pat :: * -> * #

Methods

from :: Pat -> Rep Pat x #

to :: Rep Pat x -> Pat #

Generic Type 

Associated Types

type Rep Type :: * -> * #

Methods

from :: Type -> Rep Type x #

to :: Rep Type x -> Type #

Generic Dec 

Associated Types

type Rep Dec :: * -> * #

Methods

from :: Dec -> Rep Dec x #

to :: Rep Dec x -> Dec #

Generic Name 

Associated Types

type Rep Name :: * -> * #

Methods

from :: Name -> Rep Name x #

to :: Rep Name x -> Name #

Generic FunDep 

Associated Types

type Rep FunDep :: * -> * #

Methods

from :: FunDep -> Rep FunDep x #

to :: Rep FunDep x -> FunDep #

Generic TyVarBndr 

Associated Types

type Rep TyVarBndr :: * -> * #

Generic InjectivityAnn 

Associated Types

type Rep InjectivityAnn :: * -> * #

Generic Overlap 

Associated Types

type Rep Overlap :: * -> * #

Methods

from :: Overlap -> Rep Overlap x #

to :: Rep Overlap x -> Overlap #

Generic DerivStrategy 

Associated Types

type Rep DerivStrategy :: * -> * #

Generic () 

Associated Types

type Rep () :: * -> * #

Methods

from :: () -> Rep () x #

to :: Rep () x -> () #

Generic Void 

Associated Types

type Rep Void :: * -> * #

Methods

from :: Void -> Rep Void x #

to :: Rep Void x -> Void #

Generic ExitCode 

Associated Types

type Rep ExitCode :: * -> * #

Methods

from :: ExitCode -> Rep ExitCode x #

to :: Rep ExitCode x -> ExitCode #

Generic All 

Associated Types

type Rep All :: * -> * #

Methods

from :: All -> Rep All x #

to :: Rep All x -> All #

Generic Any 

Associated Types

type Rep Any :: * -> * #

Methods

from :: Any -> Rep Any x #

to :: Rep Any x -> Any #

Generic Fixity 

Associated Types

type Rep Fixity :: * -> * #

Methods

from :: Fixity -> Rep Fixity x #

to :: Rep Fixity x -> Fixity #

Generic Associativity 

Associated Types

type Rep Associativity :: * -> * #

Generic SourceUnpackedness 
Generic SourceStrictness 
Generic DecidedStrictness 
Generic Extension 

Associated Types

type Rep Extension :: * -> * #

Generic ForeignSrcLang 

Associated Types

type Rep ForeignSrcLang :: * -> * #

Generic ModName 

Associated Types

type Rep ModName :: * -> * #

Methods

from :: ModName -> Rep ModName x #

to :: Rep ModName x -> ModName #

Generic PkgName 

Associated Types

type Rep PkgName :: * -> * #

Methods

from :: PkgName -> Rep PkgName x #

to :: Rep PkgName x -> PkgName #

Generic Module 

Associated Types

type Rep Module :: * -> * #

Methods

from :: Module -> Rep Module x #

to :: Rep Module x -> Module #

Generic OccName 

Associated Types

type Rep OccName :: * -> * #

Methods

from :: OccName -> Rep OccName x #

to :: Rep OccName x -> OccName #

Generic NameFlavour 

Associated Types

type Rep NameFlavour :: * -> * #

Generic NameSpace 

Associated Types

type Rep NameSpace :: * -> * #

Generic Loc 

Associated Types

type Rep Loc :: * -> * #

Methods

from :: Loc -> Rep Loc x #

to :: Rep Loc x -> Loc #

Generic Info 

Associated Types

type Rep Info :: * -> * #

Methods

from :: Info -> Rep Info x #

to :: Rep Info x -> Info #

Generic ModuleInfo 

Associated Types

type Rep ModuleInfo :: * -> * #

Generic Fixity 

Associated Types

type Rep Fixity :: * -> * #

Methods

from :: Fixity -> Rep Fixity x #

to :: Rep Fixity x -> Fixity #

Generic FixityDirection 
Generic Lit 

Associated Types

type Rep Lit :: * -> * #

Methods

from :: Lit -> Rep Lit x #

to :: Rep Lit x -> Lit #

Generic Body 

Associated Types

type Rep Body :: * -> * #

Methods

from :: Body -> Rep Body x #

to :: Rep Body x -> Body #

Generic Guard 

Associated Types

type Rep Guard :: * -> * #

Methods

from :: Guard -> Rep Guard x #

to :: Rep Guard x -> Guard #

Generic Stmt 

Associated Types

type Rep Stmt :: * -> * #

Methods

from :: Stmt -> Rep Stmt x #

to :: Rep Stmt x -> Stmt #

Generic Range 

Associated Types

type Rep Range :: * -> * #

Methods

from :: Range -> Rep Range x #

to :: Rep Range x -> Range #

Generic DerivClause 

Associated Types

type Rep DerivClause :: * -> * #

Generic TypeFamilyHead 

Associated Types

type Rep TypeFamilyHead :: * -> * #

Generic TySynEqn 

Associated Types

type Rep TySynEqn :: * -> * #

Methods

from :: TySynEqn -> Rep TySynEqn x #

to :: Rep TySynEqn x -> TySynEqn #

Generic FamFlavour 

Associated Types

type Rep FamFlavour :: * -> * #

Generic Foreign 

Associated Types

type Rep Foreign :: * -> * #

Methods

from :: Foreign -> Rep Foreign x #

to :: Rep Foreign x -> Foreign #

Generic Callconv 

Associated Types

type Rep Callconv :: * -> * #

Methods

from :: Callconv -> Rep Callconv x #

to :: Rep Callconv x -> Callconv #

Generic Safety 

Associated Types

type Rep Safety :: * -> * #

Methods

from :: Safety -> Rep Safety x #

to :: Rep Safety x -> Safety #

Generic Pragma 

Associated Types

type Rep Pragma :: * -> * #

Methods

from :: Pragma -> Rep Pragma x #

to :: Rep Pragma x -> Pragma #

Generic Inline 

Associated Types

type Rep Inline :: * -> * #

Methods

from :: Inline -> Rep Inline x #

to :: Rep Inline x -> Inline #

Generic RuleMatch 

Associated Types

type Rep RuleMatch :: * -> * #

Generic Phases 

Associated Types

type Rep Phases :: * -> * #

Methods

from :: Phases -> Rep Phases x #

to :: Rep Phases x -> Phases #

Generic RuleBndr 

Associated Types

type Rep RuleBndr :: * -> * #

Methods

from :: RuleBndr -> Rep RuleBndr x #

to :: Rep RuleBndr x -> RuleBndr #

Generic AnnTarget 

Associated Types

type Rep AnnTarget :: * -> * #

Generic SourceUnpackedness 
Generic SourceStrictness 
Generic DecidedStrictness 
Generic Con 

Associated Types

type Rep Con :: * -> * #

Methods

from :: Con -> Rep Con x #

to :: Rep Con x -> Con #

Generic Bang 

Associated Types

type Rep Bang :: * -> * #

Methods

from :: Bang -> Rep Bang x #

to :: Rep Bang x -> Bang #

Generic PatSynDir 

Associated Types

type Rep PatSynDir :: * -> * #

Generic PatSynArgs 

Associated Types

type Rep PatSynArgs :: * -> * #

Generic FamilyResultSig 
Generic TyLit 

Associated Types

type Rep TyLit :: * -> * #

Methods

from :: TyLit -> Rep TyLit x #

to :: Rep TyLit x -> TyLit #

Generic Role 

Associated Types

type Rep Role :: * -> * #

Methods

from :: Role -> Rep Role x #

to :: Rep Role x -> Role #

Generic AnnLookup 

Associated Types

type Rep AnnLookup :: * -> * #

Generic [a] 

Associated Types

type Rep [a] :: * -> * #

Methods

from :: [a] -> Rep [a] x #

to :: Rep [a] x -> [a] #

Generic (Maybe a) 

Associated Types

type Rep (Maybe a) :: * -> * #

Methods

from :: Maybe a -> Rep (Maybe a) x #

to :: Rep (Maybe a) x -> Maybe a #

Generic (Par1 p) 

Associated Types

type Rep (Par1 p) :: * -> * #

Methods

from :: Par1 p -> Rep (Par1 p) x #

to :: Rep (Par1 p) x -> Par1 p #

Generic (Complex a) 

Associated Types

type Rep (Complex a) :: * -> * #

Methods

from :: Complex a -> Rep (Complex a) x #

to :: Rep (Complex a) x -> Complex a #

Generic (Min a) 

Associated Types

type Rep (Min a) :: * -> * #

Methods

from :: Min a -> Rep (Min a) x #

to :: Rep (Min a) x -> Min a #

Generic (Max a) 

Associated Types

type Rep (Max a) :: * -> * #

Methods

from :: Max a -> Rep (Max a) x #

to :: Rep (Max a) x -> Max a #

Generic (First a) 

Associated Types

type Rep (First a) :: * -> * #

Methods

from :: First a -> Rep (First a) x #

to :: Rep (First a) x -> First a #

Generic (Last a) 

Associated Types

type Rep (Last a) :: * -> * #

Methods

from :: Last a -> Rep (Last a) x #

to :: Rep (Last a) x -> Last a #

Generic (WrappedMonoid m) 

Associated Types

type Rep (WrappedMonoid m) :: * -> * #

Generic (Option a) 

Associated Types

type Rep (Option a) :: * -> * #

Methods

from :: Option a -> Rep (Option a) x #

to :: Rep (Option a) x -> Option a #

Generic (NonEmpty a) 

Associated Types

type Rep (NonEmpty a) :: * -> * #

Methods

from :: NonEmpty a -> Rep (NonEmpty a) x #

to :: Rep (NonEmpty a) x -> NonEmpty a #

Generic (ZipList a) 

Associated Types

type Rep (ZipList a) :: * -> * #

Methods

from :: ZipList a -> Rep (ZipList a) x #

to :: Rep (ZipList a) x -> ZipList a #

Generic (Identity a) 

Associated Types

type Rep (Identity a) :: * -> * #

Methods

from :: Identity a -> Rep (Identity a) x #

to :: Rep (Identity a) x -> Identity a #

Generic (Dual a) 

Associated Types

type Rep (Dual a) :: * -> * #

Methods

from :: Dual a -> Rep (Dual a) x #

to :: Rep (Dual a) x -> Dual a #

Generic (Endo a) 

Associated Types

type Rep (Endo a) :: * -> * #

Methods

from :: Endo a -> Rep (Endo a) x #

to :: Rep (Endo a) x -> Endo a #

Generic (Sum a) 

Associated Types

type Rep (Sum a) :: * -> * #

Methods

from :: Sum a -> Rep (Sum a) x #

to :: Rep (Sum a) x -> Sum a #

Generic (Product a) 

Associated Types

type Rep (Product a) :: * -> * #

Methods

from :: Product a -> Rep (Product a) x #

to :: Rep (Product a) x -> Product a #

Generic (First a) 

Associated Types

type Rep (First a) :: * -> * #

Methods

from :: First a -> Rep (First a) x #

to :: Rep (First a) x -> First a #

Generic (Last a) 

Associated Types

type Rep (Last a) :: * -> * #

Methods

from :: Last a -> Rep (Last a) x #

to :: Rep (Last a) x -> Last a #

Generic (Tree a) 

Associated Types

type Rep (Tree a) :: * -> * #

Methods

from :: Tree a -> Rep (Tree a) x #

to :: Rep (Tree a) x -> Tree a #

Generic (ViewL a) 

Associated Types

type Rep (ViewL a) :: * -> * #

Methods

from :: ViewL a -> Rep (ViewL a) x #

to :: Rep (ViewL a) x -> ViewL a #

Generic (ViewR a) 

Associated Types

type Rep (ViewR a) :: * -> * #

Methods

from :: ViewR a -> Rep (ViewR a) x #

to :: Rep (ViewR a) x -> ViewR a #

Generic (Either a b) 

Associated Types

type Rep (Either a b) :: * -> * #

Methods

from :: Either a b -> Rep (Either a b) x #

to :: Rep (Either a b) x -> Either a b #

Generic (V1 k p) 

Associated Types

type Rep (V1 k p) :: * -> * #

Methods

from :: V1 k p -> Rep (V1 k p) x #

to :: Rep (V1 k p) x -> V1 k p #

Generic (U1 k p) 

Associated Types

type Rep (U1 k p) :: * -> * #

Methods

from :: U1 k p -> Rep (U1 k p) x #

to :: Rep (U1 k p) x -> U1 k p #

Generic (a, b) 

Associated Types

type Rep (a, b) :: * -> * #

Methods

from :: (a, b) -> Rep (a, b) x #

to :: Rep (a, b) x -> (a, b) #

Generic (Arg a b) 

Associated Types

type Rep (Arg a b) :: * -> * #

Methods

from :: Arg a b -> Rep (Arg a b) x #

to :: Rep (Arg a b) x -> Arg a b #

Generic (WrappedMonad m a) 

Associated Types

type Rep (WrappedMonad m a) :: * -> * #

Methods

from :: WrappedMonad m a -> Rep (WrappedMonad m a) x #

to :: Rep (WrappedMonad m a) x -> WrappedMonad m a #

Generic (Proxy k t) 

Associated Types

type Rep (Proxy k t) :: * -> * #

Methods

from :: Proxy k t -> Rep (Proxy k t) x #

to :: Rep (Proxy k t) x -> Proxy k t #

Generic (Rec1 k f p) 

Associated Types

type Rep (Rec1 k f p) :: * -> * #

Methods

from :: Rec1 k f p -> Rep (Rec1 k f p) x #

to :: Rep (Rec1 k f p) x -> Rec1 k f p #

Generic (URec k (Ptr ()) p) 

Associated Types

type Rep (URec k (Ptr ()) p) :: * -> * #

Methods

from :: URec k (Ptr ()) p -> Rep (URec k (Ptr ()) p) x #

to :: Rep (URec k (Ptr ()) p) x -> URec k (Ptr ()) p #

Generic (URec k Char p) 

Associated Types

type Rep (URec k Char p) :: * -> * #

Methods

from :: URec k Char p -> Rep (URec k Char p) x #

to :: Rep (URec k Char p) x -> URec k Char p #

Generic (URec k Double p) 

Associated Types

type Rep (URec k Double p) :: * -> * #

Methods

from :: URec k Double p -> Rep (URec k Double p) x #

to :: Rep (URec k Double p) x -> URec k Double p #

Generic (URec k Float p) 

Associated Types

type Rep (URec k Float p) :: * -> * #

Methods

from :: URec k Float p -> Rep (URec k Float p) x #

to :: Rep (URec k Float p) x -> URec k Float p #

Generic (URec k Int p) 

Associated Types

type Rep (URec k Int p) :: * -> * #

Methods

from :: URec k Int p -> Rep (URec k Int p) x #

to :: Rep (URec k Int p) x -> URec k Int p #

Generic (URec k Word p) 

Associated Types

type Rep (URec k Word p) :: * -> * #

Methods

from :: URec k Word p -> Rep (URec k Word p) x #

to :: Rep (URec k Word p) x -> URec k Word p #

Generic (a, b, c) 

Associated Types

type Rep (a, b, c) :: * -> * #

Methods

from :: (a, b, c) -> Rep (a, b, c) x #

to :: Rep (a, b, c) x -> (a, b, c) #

Generic (WrappedArrow a b c) 

Associated Types

type Rep (WrappedArrow a b c) :: * -> * #

Methods

from :: WrappedArrow a b c -> Rep (WrappedArrow a b c) x #

to :: Rep (WrappedArrow a b c) x -> WrappedArrow a b c #

Generic (Const k a b) 

Associated Types

type Rep (Const k a b) :: * -> * #

Methods

from :: Const k a b -> Rep (Const k a b) x #

to :: Rep (Const k a b) x -> Const k a b #

Generic (Alt k f a) 

Associated Types

type Rep (Alt k f a) :: * -> * #

Methods

from :: Alt k f a -> Rep (Alt k f a) x #

to :: Rep (Alt k f a) x -> Alt k f a #

Generic (K1 k i c p) 

Associated Types

type Rep (K1 k i c p) :: * -> * #

Methods

from :: K1 k i c p -> Rep (K1 k i c p) x #

to :: Rep (K1 k i c p) x -> K1 k i c p #

Generic ((:+:) k f g p) 

Associated Types

type Rep ((k :+: f) g p) :: * -> * #

Methods

from :: (k :+: f) g p -> Rep ((k :+: f) g p) x #

to :: Rep ((k :+: f) g p) x -> (k :+: f) g p #

Generic ((:*:) k f g p) 

Associated Types

type Rep ((k :*: f) g p) :: * -> * #

Methods

from :: (k :*: f) g p -> Rep ((k :*: f) g p) x #

to :: Rep ((k :*: f) g p) x -> (k :*: f) g p #

Generic (a, b, c, d) 

Associated Types

type Rep (a, b, c, d) :: * -> * #

Methods

from :: (a, b, c, d) -> Rep (a, b, c, d) x #

to :: Rep (a, b, c, d) x -> (a, b, c, d) #

Generic (Product k f g a) 

Associated Types

type Rep (Product k f g a) :: * -> * #

Methods

from :: Product k f g a -> Rep (Product k f g a) x #

to :: Rep (Product k f g a) x -> Product k f g a #

Generic (Sum k f g a) 

Associated Types

type Rep (Sum k f g a) :: * -> * #

Methods

from :: Sum k f g a -> Rep (Sum k f g a) x #

to :: Rep (Sum k f g a) x -> Sum k f g a #

Generic (M1 k i c f p) 

Associated Types

type Rep (M1 k i c f p) :: * -> * #

Methods

from :: M1 k i c f p -> Rep (M1 k i c f p) x #

to :: Rep (M1 k i c f p) x -> M1 k i c f p #

Generic ((:.:) k2 k1 f g p) 

Associated Types

type Rep ((k2 :.: k1) f g p) :: * -> * #

Methods

from :: (k2 :.: k1) f g p -> Rep ((k2 :.: k1) f g p) x #

to :: Rep ((k2 :.: k1) f g p) x -> (k2 :.: k1) f g p #

Generic (a, b, c, d, e) 

Associated Types

type Rep (a, b, c, d, e) :: * -> * #

Methods

from :: (a, b, c, d, e) -> Rep (a, b, c, d, e) x #

to :: Rep (a, b, c, d, e) x -> (a, b, c, d, e) #

Generic (Compose k1 k2 f g a) 

Associated Types

type Rep (Compose k1 k2 f g a) :: * -> * #

Methods

from :: Compose k1 k2 f g a -> Rep (Compose k1 k2 f g a) x #

to :: Rep (Compose k1 k2 f g a) x -> Compose k1 k2 f g a #

Generic (a, b, c, d, e, f) 

Associated Types

type Rep (a, b, c, d, e, f) :: * -> * #

Methods

from :: (a, b, c, d, e, f) -> Rep (a, b, c, d, e, f) x #

to :: Rep (a, b, c, d, e, f) x -> (a, b, c, d, e, f) #

Generic (a, b, c, d, e, f, g) 

Associated Types

type Rep (a, b, c, d, e, f, g) :: * -> * #

Methods

from :: (a, b, c, d, e, f, g) -> Rep (a, b, c, d, e, f, g) x #

to :: Rep (a, b, c, d, e, f, g) x -> (a, b, c, d, e, f, g) #