webby: A super-simple web server framework

[ apache, library, web ] [ Propose Tags ]

A super-simple, easy to use web server framework inspired by Scotty. The goals of the project are: (1) Be easy to use (2) Allow graceful exception handling (3) Parse request parameters easily and in a typed manner.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Flags

Manual Flags

NameDescriptionDefault
devDisabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.1, 0.1.2, 0.1.3, 0.2.0, 0.3.0, 0.3.1, 0.4.0, 1.0.0, 1.0.1, 1.0.2, 1.1.0, 1.1.1
Dependencies aeson (>=1.2 && <1.5), base (>=4.7 && <5), binary (>=0.8 && <0.9), bytestring (>=0.10 && <0.11), fast-logger (>=2.4 && <2.5), formatting (>=6.3 && <6.4), http-api-data (>=0.3 && <0.5), http-types (>=0.12 && <0.13), monad-logger (>=0.3 && <0.4), protolude (>=0.2 && <0.3), resourcet (>=1.2 && <1.3), text (>=1.2 && <1.3), unliftio (>=0.2.7 && <0.3), unordered-containers (>=0.2.9 && <0.3), wai (>=3.2 && <3.3) [details]
License Apache-2.0
Author
Maintainer aditya.mmy@gmail.com
Category Web
Uploaded by AdityaManthramurthy at 2019-04-02T19:21:22Z
Distributions
Downloads 4314 total (23 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2019-04-02 [all 1 reports]

Readme for webby-0.1.0.2

[back to package description]

Webby

An easy to use Haskell web-server inspired by Scotty.

Build

Clone the repo and run stack build

Example

module Main where

import qualified Data.Text                as T
import qualified Network.Wai.Handler.Warp as W
import           UnliftIO                 (liftIO)
import qualified UnliftIO.Exception       as E

import           Webby

main :: IO ()
main = do
    let routes = [ get "/api/a" (text "a")
                 , get "/api/b" (text "b")
                 , post "/api/capture/:id" (do idVal :: Int <- getCapture "id"
                                               text $ T.pack $ show idVal
                                           )
                 , get "/api/showEnv" (do env <- getAppEnv
                                          json env
                                      )
                 , get "/aaah" (liftIO $ E.throwString "oops!")
                 ]

    webbyApp <- mkWebbyApp (3::Int) routes
    putStrLn "Starting webserver..."
    W.runEnv 7000 webbyApp

You can try the example above, by cloning the repo and running the example:

$ examples/Basic.hs

In another shell, let's curl the server:

$ curl http://localhost:7000/api/a
a
$ curl http://localhost:7000/api/b
b
$ curl -XPOST http://localhost:7000/api/capture/32
32
$ curl http://localhost:7000/api/showEnv
MyEnv
$ curl http://localhost:7000/aaah
Control.Exception.Safe.throwString called with:

oops!
Called from:
  throwString (examples/Basic.hs:32:42 in main:Main)