servant-elm-0.5.0.0: Automatically derive Elm functions to query servant webservices.

Safe HaskellNone
LanguageHaskell2010

Servant.Elm.Internal.Generate

Synopsis

Documentation

data ElmOptions #

Options to configure how code is generated.

Constructors

ElmOptions 

Fields

data UrlPrefix #

Constructors

Static Text 
Dynamic 

defElmOptions :: ElmOptions #

Default options for generating Elm code.

The default options are:

{ urlPrefix =
    Static ""
, elmExportOptions =
    Elm.defaultOptions
, emptyResponseElmTypes =
    [ toElmType NoContent ]
, stringElmTypes =
    [ toElmType "" ]
}

defElmImports :: Text #

Default imports required by generated Elm code.

You probably want to include this at the top of your generated Elm module.

The default required imports are:

import Json.Decode exposing (..)
import Json.Decode.Pipeline exposing (..)
import Json.Encode
import Http
import String

generateElmForAPI :: (HasForeign LangElm ElmDatatype api, GenerateList ElmDatatype (Foreign ElmDatatype api)) => Proxy api -> [Text] #

Generate Elm code for the API with default options.

Returns a list of Elm functions to query your Servant API from Elm.

You could spit these out to a file and call them from your Elm code, but you would be better off creating a Spec with the result and using specsToDir, which handles the module name for you.

generateElmForAPIWith :: (HasForeign LangElm ElmDatatype api, GenerateList ElmDatatype (Foreign ElmDatatype api)) => ElmOptions -> Proxy api -> [Text] #

Generate Elm code for the API with custom options.

i :: Int #

generateElmForRequest :: ElmOptions -> Req ElmDatatype -> Doc #

Generate an Elm function for one endpoint.

isEmptyType :: ElmOptions -> ElmDatatype -> Bool #

Determines whether we construct an Elm function that expects an empty response body.

isElmStringType :: ElmOptions -> ElmDatatype -> Bool #

Determines whether we call toString on URL captures and query params of this type in Elm.

isElmMaybeStringType :: ElmOptions -> ElmDatatype -> Bool #

Determines whether a type is 'Maybe a' where a is something akin to a String.

stext :: Text -> Doc #

elmRecord :: [Doc] -> Doc #

elmList :: [Doc] -> Doc #