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

Options to configure how code is generated.

Constructors

ElmOptions 

Fields

data UrlPrefix Source #

Constructors

Static Text 
Dynamic 

defElmOptions :: ElmOptions Source #

Default options for generating Elm code.

The default options are:

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

defElmImports :: Text Source #

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] Source #

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] Source #

Generate Elm code for the API with custom options.

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

Generate an Elm function for one endpoint.

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

elmHeaderArg :: HeaderArg ElmDatatype -> Doc Source #

elmCaptureArg :: Segment ElmDatatype -> Doc Source #

elmQueryArg :: QueryArg ElmDatatype -> Doc Source #

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

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

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

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

mkQueryParams :: Req ElmDatatype -> Doc Source #

isEmptyType :: ElmOptions -> ElmDatatype -> Bool Source #

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

isElmStringType :: ElmOptions -> ElmDatatype -> Bool Source #

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