eved: A value level web framework

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

A value level web framework in the style of servant


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.0.1.0, 0.0.1.1, 0.0.2.0, 0.0.2.1, 0.0.3.0
Dependencies aeson (>=1.3.1.1 && <1.6), base (>=4.7 && <5), bytestring (>=0.10.8.2 && <0.11), case-insensitive (>=1.2.0.20 && <1.3), http-api-data (>=0.3.8.1 && <0.5), http-client (>=0.5.14 && <0.7), http-media (>=0.7.1.3 && <0.9), http-types (>=0.12.2 && <0.13), mtl (>=2.2.2 && <2.3), text (>=1.2.3.1 && <1.3), wai (>=3.2.1.2 && <3.3) [details]
License BSD-3-Clause
Copyright 2021 Ben Levy
Author Ben Levy
Maintainer ben@foxhound.systems
Category Web
Home page https://github.com/foxhound-systems/eved#readme
Source repo head: git clone https://github.com/foxhound-systems/eved
Uploaded by belevy at 2021-07-18T19:27:29Z
Distributions
Downloads 666 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2021-07-18 [all 1 reports]

Readme for eved-0.0.3.0

[back to package description]

Eved - A Value Level Servant Replacement

Eved is an API definition eDSL in the spirit of Servant. The main difference from Servant is that Eved is a value level API, whereas Servant relies very heavily on fancy type level programming.

Eved is highly extensible (both in terms of implementations and new terms) thanks to its utilization of the so called final tagless encoding.

Example

Api Definition

import           Data.Text              (Text)
import           Web.Eved
import qualified Web.Eved.ContentType   as CT
import qualified Web.Eved.QueryParam    as QP
import qualified Web.Eved.UrlElement    as UE

type Api m =
       (Integer -> Integer -> m Integer)
  :<|> (Text    -> Integer -> m Integer)
  :<|> (Text    -> Integer -> m Integer)

api :: Eved api m => api (Api m)
api =
      (lit "v1" .</> capture "captureNum" UE.integer .</> queryParam "arg1" QP.integer .</> get [CT.json @Integer])
 .<|> (lit "v1" .</> capture "captureText" UE.text .</> reqBody [CT.json @Integer] .</> post [CT.json @Integer])
 .<|> (lit "v2" .</> capture "captureText" UE.text .</> queryParam "arg1" QP.integer .</> get [CT.json @Integer])

Client

import           Web.Eved.Client

v1CaptureNum :<|> v1CaptureText :<|> v2CaptureText = getClient api "http://localhost:3000"

Server

import           Control.Monad.IO.Class
import           Control.Monad.Reader
import           Web.Eved.Server
import           Network.Wai.Handler.Warp

serve :: IO ()
serve = run 3000 $ server (`runReaderT` (Env 100)) handlers api

data Env = Env
    { envSecret :: Integer
    }

handlers :: (MonadIO m, MonadReader Env m) => Api m
handlers =   (\a b -> pure $ a + b)
        :<|> (\_ i -> fmap ((+) i) (asks envSecret))
        :<|> (\_ i -> pure i)

Prior Art

TODO

How to extend the language

TODO