servant-static-th-0.1.0.1: Embed a directory of static files in your application and serve them from your Servant server

Safe HaskellNone
LanguageHaskell2010

Servant.Static.TH.Internal.Api

Synopsis

Documentation

combineWithServantOrT :: NonEmpty (Q Type) -> Q Type Source #

Given a list of Q Type, combine them with Servant's '(:|)' function and return the resulting Q Type.

createApiType Source #

Arguments

:: FilePath

directory name to read files from

-> 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.

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
    :<|> "index.html" :> Get '[HTML] Html

createApiDec Source #

Arguments

:: String

name of the api type synonym

-> FilePath

directory name to read files from

-> 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")