snap-web-routes-0.5.1.0: Type safe URLs for Snap

Safe HaskellNone
LanguageHaskell2010

Snap.Snaplet.Router.REST

Description

This module provides data types useful for declaring RESTful routes. Resource is provided for the common case of resource specified by a unique identifier (for e.g. /products/3). SingletonResource is provided for resources that do not require an identifier. Typical usage would be as follows:

data AppUrl
    = User (Resource Int)
    | Profile SingletonResource
    | Login
    | Logout

This now allows you to define handlers for different end points for your resource. routeAppUrl appUrl = case appUrl of Login -> with auth handleLogin -- /login Logout -> with auth handleLogout -- /logout User Index -> handleUserIndex -- /user User New -> handleUserNew -- /user/new User (Show n) -> handleUserShow n -- /user/:Int User (Edit n) -> handleUserEdit n -- /user/:Int/edit Profile ShowS -> handleProfileShow -- /profile Profile NewS -> handleProfileNew -- /profile/new Profile EditS -> handleProfileEdit -- /profile/edit

Synopsis

Documentation

data PathInfo id => Resource id Source

A data type to represent RESTful resources that have a unique identifier. The data type used as the identifier must be an instance of PathInfo.

Constructors

Index 
New 
Show id 
Edit id 

Instances

(Eq id, PathInfo id) => Eq (Resource id) 
(Read id, PathInfo id) => Read (Resource id) 
(Show id, PathInfo id) => Show (Resource id) 
PathInfo id => PathInfo (Resource id) 

data SingletonResource Source

A data type to represent singleton RESTful resources. Generally these are identified in some other way, often the user's session.

Constructors

ShowS 
NewS 
EditS