rowdy-yesod-0.0.1.1: An EDSL for web application routes.
Safe HaskellNone
LanguageHaskell2010

Rowdy.Yesod

Description

Use your Rowdy route definitions with Yesod web applications.

Synopsis

Documentation

type Dsl = RouteDsl String PathPiece Endpoint Source #

We specialize the RouteDsl type to this as a shorthand.

toYesod :: Dsl () -> [ResourceTree String] Source #

Convert a RouteDsl into a representation that Yesod can use.

mkYesod App $ toYesod $ do
    get RootR
    "users" // do
       resource UserIndex [get, post]
       -- etc...

GHC freaks out if you try to use a type defined in the same module as the route. Ensure that all types you use in the route are defined in an imported module.

Since: 0.0.1.0

get :: String -> Dsl () Source #

We support the most common HTTP verbs. Each of get, put, post, and delete are given a String that represents the resource they are acting for. The generated route type uses that resource as a constructor. The generated dispatcher expects to see functions with the lowercase verb as a prefix to the resource name. As an example:

get HelloR

Will create a route type HelloR and expect a handler getHelloR to be defined.

Since: 0.0.1.0

put :: String -> Dsl () Source #

We support the most common HTTP verbs. Each of get, put, post, and delete are given a String that represents the resource they are acting for. The generated route type uses that resource as a constructor. The generated dispatcher expects to see functions with the lowercase verb as a prefix to the resource name. As an example:

get HelloR

Will create a route type HelloR and expect a handler getHelloR to be defined.

Since: 0.0.1.0

post :: String -> Dsl () Source #

We support the most common HTTP verbs. Each of get, put, post, and delete are given a String that represents the resource they are acting for. The generated route type uses that resource as a constructor. The generated dispatcher expects to see functions with the lowercase verb as a prefix to the resource name. As an example:

get HelloR

Will create a route type HelloR and expect a handler getHelloR to be defined.

Since: 0.0.1.0

delete :: String -> Dsl () Source #

We support the most common HTTP verbs. Each of get, put, post, and delete are given a String that represents the resource they are acting for. The generated route type uses that resource as a constructor. The generated dispatcher expects to see functions with the lowercase verb as a prefix to the resource name. As an example:

get HelloR

Will create a route type HelloR and expect a handler getHelloR to be defined.

Since: 0.0.1.0

doVerb :: Verb -> String -> Dsl () Source #

Create an endpoint with the given named resource and verb.

Since: 0.0.1.0

subsite :: String -> String -> String -> Dsl () Source #

Create a subsite with the given name, type, and accessor function name to get the underlying application.

Since: 0.0.1.0

capture :: forall typ. Typeable typ => PathPiece Source #

Capture a dynamic path piece and parse it as the provided type. This function is intended to be used with the TypeApplications language extension.

"users" // do
    resource UserIndexR [get, post]
    capture @UserId $ do
        resource UserR [get, put, delete]
        "posts" // do
            resource PostR [get, post]

Since: 0.0.1.0

captureP :: forall typ. Typeable typ => Proxy typ -> PathPiece Source #

A version of capture that accepts an explicit Proxy argument. Use this if you don't like the TypeApplications syntax, or have a proxy on hand already.

Since: 0.0.1.0

resource :: String -> [String -> Dsl ()] -> Dsl () Source #

Define a number of handlers for the named resource. The following code block:

do get HelloR
   put HelloR
   post HelloR
   delete HelloR

is equivalent to this shorter form:

resource HelloR [get, put, post, delete]

Since: 0.0.1.0

attr :: String -> Dsl () -> Dsl () Source #

Attach a route attribute to every element in the given DSL.

Since: 0.0.1.0

(/!) :: String -> Dsl () -> Dsl () infixr 8 Source #

An infix operator alias for attr.

"admin" / "admin" ! do
     resource AdminR [get, put, post]

Since: 0.0.1.0

(!) :: Dsl () -> String -> Dsl () infixl 8 Source #

Provide an inline attribute to the given route.

get HelloR ! "friendly"

(//) :: capture -> RouteDsl nest capture endpoint () -> RouteDsl nest capture endpoint () infixr 5 #

An infix operator for pathComponent.

Since: rowdy-0.0.1.0

(/:) :: nest -> RouteDsl nest capture endpoint () -> RouteDsl nest capture endpoint () infixr 7 #

An infix operator alias for nest.

Since: rowdy-0.0.1.0

data Endpoint Source #

An endpoint in the Yesod model.

Constructors

MkResource Verb String

A resource identified by a Verb and a String name.

MkSubsite String String String

A subsite.

Instances

Instances details
Eq Endpoint Source # 
Instance details

Defined in Rowdy.Yesod.Internal

Show Endpoint Source # 
Instance details

Defined in Rowdy.Yesod.Internal

data PathPiece Source #

The type of things that can affect a path.

Constructors

Literal String

Static string literals.

Capture Type

Dynamic captures.

Attr String

Route attributes. Not technically part of the path, but applies to everything below it in the tree.

Instances

Instances details
Eq PathPiece Source # 
Instance details

Defined in Rowdy.Yesod.Internal

Show PathPiece Source # 
Instance details

Defined in Rowdy.Yesod.Internal

IsString PathPiece Source # 
Instance details

Defined in Rowdy.Yesod.Internal

data Type where Source #

A value containing a Proxy of some Haskell type.

Constructors

Type :: Typeable t => Proxy t -> Type 

Instances

Instances details
Eq Type Source # 
Instance details

Defined in Rowdy.Yesod.Internal

Methods

(==) :: Type -> Type -> Bool #

(/=) :: Type -> Type -> Bool #

Show Type Source # 
Instance details

Defined in Rowdy.Yesod.Internal

Methods

showsPrec :: Int -> Type -> ShowS #

show :: Type -> String #

showList :: [Type] -> ShowS #

data Verb Source #

The HTTP verbs.

Constructors

Get 
Put 
Post 
Delete 

Instances

Instances details
Eq Verb Source # 
Instance details

Defined in Rowdy.Yesod.Internal

Methods

(==) :: Verb -> Verb -> Bool #

(/=) :: Verb -> Verb -> Bool #

Show Verb Source # 
Instance details

Defined in Rowdy.Yesod.Internal

Methods

showsPrec :: Int -> Verb -> ShowS #

show :: Verb -> String #

showList :: [Verb] -> ShowS #