@hackage miku2016.3.17
A minimum web dev DSL
Categories
License
BSD-3-Clause
Maintainer
Jinjing Wang <nfjinjing@gmail.com>
Links
Versions
- 2016.3.17 Wed, 16 Mar 2016
- 2016.3.16.1 Wed, 16 Mar 2016
- 2016.3.16 Wed, 16 Mar 2016
- 2014.11.17 Mon, 17 Nov 2014
- 2014.5.19 Mon, 19 May 2014
- 2014.4.14 Mon, 14 Apr 2014 Show all…
Installation
Tested Compilers
Dependencies (10)
- base >4 && <=6
- blaze-builder >=0.4.0.1
- bytestring
- case-insensitive >=1.2.0.5
- containers
- filepath >=1.4.0.0 Show all…
Dependents (2)
@hackage/acme-everything, @hackage/geek
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
askdefined inReaderTmonad to get theRequest, then use helper methods forwaito query it. Responseis inStateT,htmlandtextare 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.