Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/foxhound-systems/eved
Eved is an API definition eDSL in the spirit of Servant
https://github.com/foxhound-systems/eved
haskell
Last synced: about 10 hours ago
JSON representation
Eved is an API definition eDSL in the spirit of Servant
- Host: GitHub
- URL: https://github.com/foxhound-systems/eved
- Owner: foxhound-systems
- License: bsd-3-clause
- Created: 2021-04-06T15:30:07.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-10-25T22:05:19.000Z (about 3 years ago)
- Last Synced: 2024-08-10T10:11:53.878Z (3 months ago)
- Topics: haskell
- Language: Haskell
- Homepage: https://hackage.haskell.org/package/eved
- Size: 68.4 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Eved - A Value Level Servant Replacement
Eved is an API definition eDSL in the spirit of [Servant](https://hackage.haskell.org/package/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
```haskell
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 UEtype 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
```haskell
import Web.Eved.Clientv1CaptureNum :<|> v1CaptureText :<|> v2CaptureText = getClient api "http://localhost:3000"
```### Server
```haskell
import Control.Monad.IO.Class
import Control.Monad.Reader
import Web.Eved.Server
import Network.Wai.Handler.Warpserve :: IO ()
serve = run 3000 $ server (`runReaderT` (Env 100)) handlers apidata 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