snap-predicates: Declarative routing for Snap.

[ library, snap ] [ Propose Tags ]

Provides the definition of a predicate type-class together with several concrete implementations which are used to constrain the set of possible Snap handlers in a type-safe way.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0, 0.2.0, 0.3.0, 0.3.1
Dependencies attoparsec (>=0.10), base (>=4 && <5), bytestring (>=0.9), case-insensitive (>=1.0), containers (>=0.5), monads-tf (>=0.1), snap-core (>=0.9), text (>=0.11), transformers (>=0.3) [details]
License MIT
Copyright Copyright (c) 2013 Toralf Wittner, Brendan Hay
Author Toralf Wittner, Brendan Hay
Maintainer Toralf Wittner <tw@dtex.org>
Category Snap
Source repo head: git clone git://github.com/twittner/snap-predicates.git
Uploaded by ToralfWittner at 2013-05-19T21:36:13Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 3051 total (12 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]

Readme for snap-predicates-0.3.0

[back to package description]

Snap-Predicates

This library provides the definition of a type-class Predicate together with several concrete implementations which are used to constrain the set of possible Snap handlers in a type-safe way.

A module Snap.Predicates.Tutorial is included, outlining the basic concepts.

Example Usage

main :: IO ()
main = do
    mapM_ putStrLn (showRoutes sitemap)
    quickHttpServe (route . expandRoutes $ sitemap)

sitemap :: Routes Snap ()
sitemap = do
    head_ "/status" (const $ return ())

    get  "/foo" listFoo $
        Accept Text Plain :&: ParamDef "off" 0 :&: ParamDef "size" 100

    post "/foo" createFoo $
        Accept Text Plain :&: ContentType Application Protobuf

listFoo :: MediaType Text Plain :*: Int :*: Int -> Snap ()
listFoo (_mt :*: _off :*: _size) = return ()

createFoo :: MediaType Text Plain :*: Content Application Protobuf -> Snap ()
createFoo (_mt :*: _ct) = return ()