Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- servantDefs :: forall {k} (api :: k). Elmable api => Proxy api -> Set Definition
- generateElm :: forall {k} (api :: k). Elmable api => OsPath -> Proxy api -> IO ()
- class Elmable (e :: k) where
- endpoints :: [Param] -> Definitions ()
- class IsParam (a :: k) where
- data Param
- data PathParam
- data HeaderParam
- data QP
Generating Elm Clients
servantDefs :: forall {k} (api :: k). Elmable api => Proxy api -> Set Definition Source #
This function will traverse the api
type, generating elm definitions for:
- Http requests for each endpoint, including encoders and decoders for anonymous elm types.
- Named Elm types (i.e. Any
Specification
that is bound to a name usingJsonLet
- Decoders and Encoders for named elm types.
You can consume the resulting Definition
s using the
elm-syntax:Language.Elm.Pretty
module.
:: forall {k} (api :: k). Elmable api | |
=> OsPath | The directory in which to deposit Elm code. |
-> Proxy api | |
-> IO () |
"Batteries included" way to generate some Elm code on disk in a given a directory. The directory should be dedicated to the generated Elm code and you shouldn't try to store anything else in that directory, Elm files or otherwise.
This function will succeed without error if (and only if) the directory already exists and its contents exactly match what would be generated anyway.
If the files on disk are wrong, then an error is thrown, and the files are unmodified.
If the directory does not exist, then it is created and the Elm code is generated inside the directory, then an error is thrown.
The intent is that you can use this function (thinly wrapped with the appropriate directory and api spec) as the main function for a test suite, where the "test" is that the files on disk are already correct. We throw an error even in the case where we generate files for you because, for instance, you wouldn't want CI to be generating these files when you forgot to check them in in the first place.
Extensions
The symbols in this section are mainly exposed in case you are using
some extensions to the standard servant types and need to build some
companion extensions to generate proper Elm types for them. For most
normal usage you will probably just use servantDefs
.
class Elmable (e :: k) where Source #
Class of servant APIs for which Elm client code can be generated.
endpoints :: [Param] -> Definitions () Source #
Collect all the Elm definitions needed to implement a client for
the API. This is called recursively on our walk down the API tree,
and the [
argument contains all the request parameters
(like Param
]Capture
, ReqBody'
, etc) that have been encountered so far on
whatever particular branch . It will start out empty at the API root.
Instances
class IsParam (a :: k) where Source #
Obtain a value-level request parameter type from the type-level servant parameter type.
param :: Definitions Param Source #
Instances
data HeaderParam Source #
Instances
Eq HeaderParam Source # | |
Defined in Data.JsonSpec.Elm.Servant (==) :: HeaderParam -> HeaderParam -> Bool # (/=) :: HeaderParam -> HeaderParam -> Bool # |