servant-elm-0.6.0.0: 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 ""
, elmAlterations =
    Elm.defaultTypeAlterations
, emptyResponseElmTypes =
    [ getType (Proxy :: Proxy ()) ]
, stringElmTypes =
    [ getType (Proxy :: Proxy String)
    , getType (Proxy :: Proxy T.Text) ]
}

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
import Json.Encode exposing (Value)
-- The following module comes from bartavelle/json-helpers
import Json.Helpers exposing (..)
import Dict exposing (Dict)
import Set
import Http
import String
import Url.Builder

generateElmModuleWith :: (HasForeign LangElm EType api, GenerateList EType (Foreign EType api)) => ElmOptions -> Namespace -> Text -> FilePath -> [DefineElm] -> Proxy api -> IO () Source #

Helper to generate a complete Elm module given a list of Elm type definitions and an API.

generateElmModule :: (HasForeign LangElm EType api, GenerateList EType (Foreign EType api)) => Namespace -> Text -> FilePath -> [DefineElm] -> Proxy api -> IO () Source #

Calls generateElmModuleWith with defElmOptions.

generateElmForAPI :: (HasForeign LangElm EType api, GenerateList EType (Foreign EType 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 EType api, GenerateList EType (Foreign EType api)) => ElmOptions -> Proxy api -> [Text] Source #

Generate Elm code for the API with custom options.

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

Generate an Elm function for one endpoint.

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

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

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

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

isElmMaybeStringType :: ElmOptions -> EType -> Bool Source #

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