The miku package

[Tags: bsd3, library]

A simple library for fast web prototyping in Haskell.


[Skip to ReadMe]

Properties

Versions2011.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
Change logchangelog.md
Dependenciesair (>=2014.5.19), air-th, base (>4 && <=99), bytestring, containers, data-default, hack2 (>=2012.1.19), hack2-contrib (>=2012.1.19), mtl [details]
LicenseBSD3
AuthorJinjing Wang
MaintainerJinjing Wang <nfjinjing@gmail.com>
CategoryWeb
Home pagehttps://github.com/nfjinjing/miku
UploadedMon Nov 17 11:14:59 UTC 2014 by JinjingWang
DistributionsNixOS:2014.11.17
Downloads1608 total (107 in last 30 days)
Votes
0 []
StatusDocs uploaded by user
Build status unknown [no reports yet]

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees

Readme for miku-2014.11.17

miku

A tiny web dev DSL

Example

{-# LANGUAGE OverloadedStrings #-}

import Network.Miku
import Hack2.Handler.SnapServer

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

Installation

cabal update
cabal install miku
cabal install hack2-handler-snap-server

-- 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

{-# LANGUAGE OverloadedStrings #-}

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

import Network.Miku
import Hack2.Handler.SnapServer

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/miku/hello will output
-- [("user","miku"),("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

import Hack2.Contrib.Middleware.SimpleAccessLogger

middleware - simple_access_logger Nothing

Convert miku into a hack2 application

-- in Network.Miku.Engine

miku :: MikuMonad -> Application

Hints

Reference