miku: A minimum web dev DSL

[ bsd3, library, web ] [ Propose Tags ] [ Report a vulnerability ]

A simple library for fast web prototyping in Haskell.


[Skip to Readme]

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 base (>4 && <=6), blaze-builder (>=0.4.0.1), bytestring, case-insensitive (>=1.2.0.5), containers, filepath (>=1.4.0.0), http-types (>=0.9), mtl, wai, wai-extra [details]
Tested with ghc ==7.10.3
License BSD-3-Clause
Author Jinjing Wang
Maintainer Jinjing Wang <nfjinjing@gmail.com>
Category Web
Home page https://github.com/nfjinjing/miku
Source repo head: git clone git://github.com/nfjinjing/miku.git
Uploaded by JinjingWang at 2016-03-16T23:22:56Z
Distributions
Reverse Dependencies 2 direct, 1 indirect [details]
Downloads 9996 total (16 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2016-03-16 [all 1 reports]

Readme for miku-2016.3.17

[back to package description]

miku

A tiny web dev DSL

Example

{-# LANGUAGE OverloadedStrings #-}

import           Network.Miku
import           Network.Wai.Handler.Warp (run)

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

Installation

cabal update
cabal install miku
cabal install warp 

-- 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/test/RouteExample.hs

Routes

Verbs

{-# LANGUAGE OverloadedStrings #-}

import Network.Miku
import Network.Miku.Utils ((-))
import Network.Wai.Handler.Warp (run)
import Prelude hiding ((-))

main = run 3000 . 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")]

WAI integration

Use WAI middleware

import Network.Wai.Middleware.RequestLogger

middleware logStdout

Convert miku into a WAI application

-- in Network.Miku.Engine

miku :: MikuMonad -> 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 Request, then use helper methods for wai 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.

Reference