servant-serf: Generates a servant API module

[ code-generation, library, mit, program ] [ Propose Tags ]

A preprocessor which will parse a psuedo-haskell module with imports and generate a module with exports a Route type and a handler function

[Skip to Readme]
Versions [RSS] [faq] 0.0.1, 0.0.2, 0.0.3, 0.1.0, 0.1.1, 0.2.0 (info)
Dependencies attoparsec, base (<=, hpack, mtl, optparse-applicative, regex-base, regex-tdfa (>=, text [details]
License MIT
Maintainer ACI Learning
Category Code Generation
Home page
Bug tracker
Source repo head: git clone
Uploaded by fozworth at 2021-09-21T01:10:23Z
Distributions NixOS:0.1.1
Executables servant-serf
Downloads 465 total (18 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs not available [build log]
Last success reported on 2021-09-21 [all 1 reports]


Maintainer's Corner

For package maintainers and hackage trustees


Readme for servant-serf-0.2.0

[back to package description]

🚜 servant-serf



{-# OPTIONS_GHC -F -pgmF servant-serf
  -optF --package-name=servant-serf-example
  -optF --is-handler-module=Foo.Handler.*
  -optF --ghc-options=-freduction-depth=0

module Foo.Api where

import Foo.Handler.HelloWorld
import Foo.Handler.GoodbyeWorld


{-# OPTIONS_GHC -fno-warn-partial-type-signatures -freduction-depth=0 #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE ExplicitNamespaces #-}
{-# LANGUAGE TypeOperators #-}
module Foo.Api (type Route, handler) where

import Servant ((:<|>)((:<|>)))
import qualified GHC.Stack as Stack
import qualified Servant

import qualified Foo.Handler.HelloWorld
import qualified Foo.Handler.GoodbyeWorld

type Route
  = Foo.Handler.HelloWorld.Route
  :<|> Foo.Handler.GoodbyeWorld.Route

handler :: Stack.HasCallStack => Servant.ServerT Route _
  = Foo.Handler.HelloWorld.handler
  :<|> Foo.Handler.GoodbyeWorld.handler

Module discovery:

When the preprocessor runs it looks at your package.yaml and the is-handler-module option to determine which modules should be imported to the generated API module. Because the ordering of the routes matters, you must explicitly import each route in the order they will appear in the Route type. If you haven't yet imported a module which servant-serf has disovered, you'll receive a helpful error message like the following:

/home/zach/Dev/servant-serf/servant-serf-example//tmp/ghc32747_0/ghc_1.hspp:9:11: error:
    • Missing handler imports. Consider adding the following imports to the file src/Foo/Api.hs
       or updating the is_handler_module regular expression in your .servant-serf.toml
      import Foo.Handler.GoodbyeWorld