HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleservant-static-th-1.0.0.0Haskell2010

Servant.Static.TH.Internal.Api

  • 5 values
valuecreateApiType
  1. :: FilePath

    directory name to read files from

  2. -> Q Type
#

Take a template directory argument as a FilePath and create a Servant type representing the files in the directory. Empty directories will be ignored. index.html files will also be served at the root.

For example, assume the following directory structure:

  $ tree dir/
  dir/
  ├── js
  │   └── test.js
  └── index.html

createApiType is used like the following:

  {-# LANGUAGE DataKinds #-}
  {-# LANGUAGE TemplateHaskell #-}

  type FrontEndAPI = $(createApiType "dir")

At compile time, it will expand to the following:

  type FrontEndAPI =
         "js" :> "test.js" :> Get '[JS] ByteString
    :<|> Get '[HTML] Html
    :<|> "index.html" :> Get '[HTML] Html
valuecreateApiDec
  1. :: String

    name of the api type synonym

  2. -> FilePath

    directory name to read files from

  3. -> Q [Dec]
#

This is similar to createApiType, but it creates the whole type synonym declaration.

Given the following code:

  {-# LANGUAGE DataKinds #-}
  {-# LANGUAGE TemplateHaskell #-}

  $(createApiDec "FrontAPI" "dir")

You can think of it as expanding to the following:

  type FrontAPI = $(createApiType "dir")