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]
Versions [faq] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.1
Dependencies aeson (>=1.2 && <1.5), base (>=4.7 && <5), binary (==0.8.*), bytestring (==0.10.*), fast-logger (==2.4.*), formatting (==6.3.*), http-api-data (>=0.3 && <0.5), http-types (==0.12.*), monad-logger (==0.3.*), protolude (==0.2.*), resourcet (==1.2.*), text (==1.2.*), unliftio (>=0.2.7 && <0.3), unordered-containers (>=0.2.9 && <0.3), wai (==3.2.*) [details]
License Apache-2.0
Author
Maintainer aditya.mmy@gmail.com
Category Web
Uploaded by AdityaManthramurthy at Mon Jun 10 05:43:15 UTC 2019
Distributions NixOS:0.1.1
Downloads 265 total (27 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2019-06-10 [all 1 reports]

Modules

[Index] [Quick Jump]

Flags

NameDescriptionDefaultType
devDisabledManual

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

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for webby-0.1.1

[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)