servant-serf: Generates a servant API module

[ library, mit, program, web ] [ 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]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.1, 0.0.2, 0.0.3, 0.1.0, 0.1.1, 0.1.2, 0.2.0, 0.2.1, 0.3.0.1, 0.3.1.0, 0.3.1.1, 0.3.1.2, 0.3.1.3, 0.3.1.4, 0.3.1.5, 0.3.1.6 (info)
Dependencies attoparsec (>=0.13.2.5), base (>=4.14.1.0 && <=5.2.0.0), hpack (>=0.34.4), mtl (>=2.2.2), optparse-applicative (>=0.15.1.0), regex-base (>=0.94.0.0), regex-tdfa (>=1.3.1.0), text (>=1.2.4.1) [details]
License MIT
Author
Maintainer ACI Learning
Category Code Generation
Home page https://github.com/EdutainmentLIVE/servant-serf#readme
Bug tracker https://github.com/EdutainmentLIVE/servant-serf/issues
Source repo head: git clone https://github.com/EdutainmentLIVE/servant-serf
Uploaded by fozworth at 2021-11-01T20:43:44Z
Distributions NixOS:0.3.1.6
Executables servant-serf
Downloads 1458 total (58 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
Last success reported on 2021-11-01 [all 1 reports]

Readme for servant-serf-0.2.1

[back to package description]

🚜 servant-serf

Example

Input:

{-# 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

Output:

{-# 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 _
handler
  = 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