servant-elm-0.4.0.1: 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.

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

elmHeaderArg :: HeaderArg ElmDatatype -> Doc #

elmCaptureArg :: Segment ElmDatatype -> Doc #

elmQueryArg :: QueryArg ElmDatatype -> Doc #

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

mkLetParams :: ElmOptions -> Req ElmDatatype -> Maybe Doc #

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

mkUrl :: ElmOptions -> [Segment ElmDatatype] -> Doc #

mkQueryParams :: Req ElmDatatype -> Doc #

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.

stext :: Text -> Doc #

elmRecord :: [Doc] -> Doc #

elmList :: [Doc] -> Doc #