Skip to content
A tiny web dev DSL
Haskell Nix
Latest commit 5d5d88b Mar 17, 2016 @nfjinjing re-organize cabal
Failed to load latest commit information.
src clean up monad type Mar 17, 2016
test clean up monad type Mar 16, 2016
.ghci update examples Mar 16, 2016
.gitignore update examples Mar 16, 2016
LICENSE init Jun 10, 2011
Nemesis.hs add dist task Mar 16, 2016
Setup.lhs init Jun 10, 2011
changelog.md fix ver Mar 17, 2016
default.nix upgrade to modern convention Mar 16, 2016
known-issues.md init Jun 10, 2011
miku.cabal re-organize cabal Mar 17, 2016
miku.nix fix ver Mar 16, 2016
readme.md release Mar 16, 2016
shell.nix upgrade to modern convention Mar 16, 2016

readme.md

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

Something went wrong with that request. Please try again.