wai-routes: This package provides typesafe URLs for Wai applications.

[ library, mit, network ] [ Propose Tags ]

This package provides typesafe URLs for Wai applications.


[Skip to Readme]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1, 0.2, 0.2.1, 0.2.2, 0.2.3, 0.2.4, 0.3.0, 0.3.1, 0.3.2, 0.3.3, 0.3.4, 0.4.0, 0.4.1, 0.5.0, 0.5.1, 0.6.0, 0.6.1, 0.6.2, 0.7.0, 0.7.1, 0.7.2, 0.7.3, 0.8.0, 0.8.1, 0.9.0, 0.9.1, 0.9.2, 0.9.3, 0.9.4, 0.9.5, 0.9.6, 0.9.7, 0.9.8, 0.9.9, 0.9.10, 0.10.0, 0.10.1, 0.10.2, 0.10.3, 0.10.4
Dependencies base (>=3 && <5), http-types, path-pieces, template-haskell, text, wai [details]
License LicenseRef-GPL
Author Anupam Jain
Maintainer ajnsit@gmail.com
Category Network
Home page https://github.com/ajnsit/wai-routes
Source repo head: git clone http://github.com/ajnsit/wai-routes
this: git clone http://github.com/ajnsit/wai-routes/tree/v0.1(tag v0.1)
Uploaded by AnupamJain at 2012-01-13T14:36:01Z
Distributions
Reverse Dependencies 2 direct, 0 indirect [details]
Downloads 26269 total (94 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for wai-routes-0.1

[back to package description]
Wai Routes (wai-routes-0.1)
============================

This package provides typesafe URLs for Wai applications.

Much of the TH functionality has been lifted from Yesod dispatching code. The aim is to provide a similar level of typesafe URL functionality to Wai applications as is available to Yesod applications.


Example Usage
=============

The following builds a simple JSON service (using Aeson for JSON conversion)


    -- A useful type synonym
    type UserId = Text

    -- Define the JSON instance
    data User = User { name::Text, uid:: UserId } deriving (Show, Read, Eq)
    instance ToJSON User where
      toJSON x = object [ "name" .= (name x), "uid" .= (uid x) ]

    -- Define the handlers
    getUserR :: UserId -> Application
    getUserR uid _req =
      return $ responseLBS statusOK headers json
      where user = User { name = "Anon Amos", uid = uid }
            json = encode user
            headers = [("Content-Type", "application/json")]

    getUsersR :: Application
    getUsersR _req =
      return $ responseLBS statusOK headers json
      where userids = (["anon","john","jane"]::[Text])
            json = encode userids
            headers = [("Content-Type", "application/json")]

    -- Generate the routing datatype and the Route instance
    -- The type generated will be named "UserRoute"
    mkRoute "User" [parseRoutes|
      /users UsersR GET
      /user/#UserId UserR GET
    |]

    -- Now you can use dispatch function (passing it your route datatype)
    main :: IO ()
    main = run 8080 $ dispatch (undefined::UserRoute) $ staticApp defaultFileServerSettings


Changelog
=========

0.1 : Intial release