Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data ElmOptions = ElmOptions {
- urlPrefix :: Text
- elmExportOptions :: Options
- emptyResponseElmTypes :: [ElmDatatype]
- stringElmTypes :: [ElmDatatype]
- defElmOptions :: ElmOptions
- defElmImports :: Text
- generateElmForAPI :: (HasForeign LangElm ElmDatatype api, GenerateList ElmDatatype (Foreign ElmDatatype api)) => Proxy api -> [Text]
- generateElmForAPIWith :: (HasForeign LangElm ElmDatatype api, GenerateList ElmDatatype (Foreign ElmDatatype api)) => ElmOptions -> Proxy api -> [Text]
- cr :: Text
- quote :: Text
- inQuotes :: Text -> Text
- generateElmForRequest :: ElmOptions -> Req ElmDatatype -> [Text]
- mkTypeSignature :: ElmOptions -> Req ElmDatatype -> Text
- mkArgsList :: Req ElmDatatype -> [Text]
- mkUrl :: Text -> ElmOptions -> [Segment ElmDatatype] -> Text
- mkLetParams :: Text -> ElmOptions -> Req ElmDatatype -> Maybe Text
- mkLetRequest :: Text -> ElmOptions -> Req ElmDatatype -> Text
- mkQueryParams :: Text -> Req ElmDatatype -> [Text]
- mkHttpRequest :: Text -> ElmOptions -> Req ElmDatatype -> (Text, [Text])
- isEmptyType :: ElmOptions -> ElmDatatype -> Bool
- isElmStringType :: ElmOptions -> ElmDatatype -> Bool
Documentation
data ElmOptions Source #
Options to configure how code is generated.
ElmOptions | |
|
defElmOptions :: ElmOptions Source #
Default options for generating Elm code.
The default options are:
{ urlPrefix = "" , 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 import Task
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 -> [Text] Source #
Generate an Elm function for one endpoint.
This function returns a list because the query function may require some supporting definitions.
mkTypeSignature :: ElmOptions -> Req ElmDatatype -> Text Source #
mkArgsList :: Req ElmDatatype -> [Text] Source #
mkLetParams :: Text -> ElmOptions -> Req ElmDatatype -> Maybe Text Source #
mkLetRequest :: Text -> ElmOptions -> Req ElmDatatype -> Text Source #
mkHttpRequest :: Text -> ElmOptions -> Req ElmDatatype -> (Text, [Text]) Source #
If the return type has a decoder, construct the request using Http.fromJson. Otherwise, construct an HTTP request that expects an empty response.
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.