miku: A minimum web dev DSL in Haskell

[ bsd3, library, web ] [ Propose Tags ]

A simple library for fast web prototyping in Haskell.


[Skip to Readme]

Modules

[Last Documentation]

  • Network
    • Network.Miku
      • Network.Miku.Config
      • Network.Miku.DSL
      • Network.Miku.Engine
      • Middleware
        • Network.Miku.Middleware.MikuRouter
      • Network.Miku.Type
      • Network.Miku.Utils

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 2011.6.11, 2011.6.12, 2011.6.15, 2011.6.18, 2011.6.19, 2011.6.20, 2011.6.24, 2012.1.19, 2012.10.27, 2014.4.14, 2014.5.19, 2014.11.17, 2016.3.16, 2016.3.16.1, 2016.3.17
Change log changelog.md
Dependencies air (>=2011.6.11), air-extra (>=2011.6.11), base (>4 && <=5), bytestring, containers, data-default, hack2 (>=2009.7.15), hack2-contrib (>=2009.8.18), mtl, utf8-string [details]
License BSD-3-Clause
Author Jinjing Wang
Maintainer Jinjing Wang <nfjinjing@gmail.com>
Category Web
Home page http://github.com/nfjinjing/miku
Uploaded by JinjingWang at 2011-06-10T07:40:20Z
Distributions
Reverse Dependencies 2 direct, 1 indirect [details]
Downloads 9715 total (34 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2016-12-27 [all 7 reports]

Readme for miku-2011.6.11

[back to package description]

miku

A tiny web dev DSL

Example

{-# LANGUAGE OverloadedStrings #-}

import Network.Miku
import Hack2.Handler.HappstackServer

main = run . miku $ get "/" (text "miku power")

Installation

cabal update
cabal install miku
cabal install hack2-handler-happstack

-- copy and paste the above example to myapp.hs

runghc myapp.hs

check: http://localhost:3000

Quick reference

https://github.com/nfjinjing/miku/blob/master/src/Test/Test.hs

Routes

Verbs

-- use - instead of $ for clarity
import Air.Light ((-))
import Prelude hiding ((-))

import Network.Miku
import Hack2.Handler.Happstack

main = run . miku - do

  get "/" - do
    -- something for a get request

  post "/" - do
    -- for a post request

  put "/" - do
    -- put ..

  delete "/" - do
    -- ..

Captures

get "/say/:user/:message" - do
  text . show =<< captures

-- /say/jinjing/hello will output
-- [("user","jinjing"),("message","hello")]

Static

-- public serve, only allows `./src`
public (Just ".") ["/src"]

Mime types

-- treat .hs extension as text/plain
mime "hs" "text/plain"

Filters

-- before takes a function of type (Env -> IO Env)
before - \e -> do
  putStrLn "before called"
  return e

-- after takes that of type (Response -> IO Response)
after return

Hack2 integration

Use hack2 middleware

-- note both etag and lambda middleware are removed ... for somce ghc 7.0 compatability ><

import Hack2.Contrib.Middleware.SimpleAccessLogger

middleware - simple_access_logger Nothing

Convert miku into a hack2 application

-- in Network.Miku.Engine

miku :: Unit -> Application

Hints

  • It's recommended to use your own html combinator / template engine. Try DIY with, e.g. moe.
  • Example view using custom html combinator (moe in this case)
  • When inspecting the request, use ask defined in ReaderT monad to get the Hack2.Environment, then use helper method defined in Hack2.Contrib.Request to query it.
  • Response is in StateT, html and text are simply helper methods that update the state, i.e. setting the response body, content-type, etc.
  • You do need to understand monad transformers to reach the full power of miku.
  • For mac users, use GHC 6.12.1 if you have trouble running the server.

Reference