twain: Tiny web application framework for WAI.

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

Twain is tiny web application framework for WAI. It provides routing, parameter parsing, and an either-like monad for composing responses.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 1.0.0.0, 2.0.0.0, 2.0.1.0, 2.1.0.0, 2.1.2.0, 2.2.0.0, 2.2.0.1
Change log changelog.md
Dependencies aeson (>=2 && <3), base (>=4.7 && <5), bytestring (>=0.10 && <0.12), case-insensitive (>=1.2 && <1.3), cookie (>=0.4 && <0.6), either (>=5.0 && <5.1), exceptions (>=0.10 && <0.11), http-types (>=0.12 && <0.13), http2 (>=5.0 && <5.4), text (>=1.2.3 && <3), time (>=1.8 && <2), transformers (>=0.5.6 && <0.7), vault (>=0.3 && <0.4), wai (>=3.2 && <3.3), wai-extra (>=3.0 && <3.2) [details]
License BSD-3-Clause
Copyright 2021 Alexander C. Mingoia
Author Alex Mingoia
Maintainer alex@alexmingoia.com
Category Web
Home page https://github.com/alexmingoia/twain#readme
Bug tracker https://github.com/alexmingoia/twain/issues
Source repo head: git clone https://github.com/alexmingoia/twain
Uploaded by alexmingoia at 2024-11-05T23:21:05Z
Distributions NixOS:2.2.0.0
Downloads 1042 total (48 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-11-06 [all 1 reports]

Readme for twain-2.2.0.1

[back to package description]

Twain

Hackage BSD3 License

Twain is a tiny web application framework for WAI.

  • ResponderM for composing responses with do notation.
  • Routing with path captures that decompose ResponderM into middleware.
  • Parameter parsing from cookies, path, query, and body.
  • Helpers for redirects, headers, status codes, and errors.
{-# language OverloadedStrings #-}

import Network.Wai.Handler.Warp (run)
import Web.Twain

main :: IO ()
main = do
  run 8080 $
    foldr ($) (notFound missing) routes

routes :: [Middleware]
routes =
  [ get "/" index
  , post "/echo/:name" echoName
  ]

index :: ResponderM a
index = send $ html "Hello World!"

echoName :: ResponderM a
echoName = do
  name <- param "name"
  send $ html $ "Hello, " <> name

missing :: ResponderM a
missing = send $ html "Not found..."