snap-predicates: Declarative routing for Snap.

[ library, snap ] [ Propose Tags ] [ Report a vulnerability ]

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

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

  • 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 LicenseRef-OtherLicense
Copyright Copyright (c) 2013 Toralf Wittner, Brendan Hay
Author Toralf Wittner, Brendan Hay
Maintainer Toralf Wittner <tw@dtex.org>
Revised Revision 1 made by ToralfWittner at 2016-01-24T13:03:29Z
Category Snap
Source repo head: git clone git@gitlab.com:twittner/snap-predicates.git
Uploaded by ToralfWittner at 2013-07-02T18:57:51Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 3122 total (15 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.1

[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 ()