| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Servant.Elm
Description
Basic usage:
import MyLib (MyServantApiType)
import Servant.Elm
spec :: Spec
spec = Spec ["Generated", "MyApi"]
(defElmImports : generateElmForAPI (Proxy :: Proxy MyServantApiType))
main :: IO ()
main = specsToDir [spec] "my-elm-dir"- generateElmForAPI :: HasElmClient layout => Proxy layout -> [String]
- generateElmForAPIWith :: HasElmClient layout => ElmOptions -> Proxy layout -> [String]
- data ElmOptions = ElmOptions {}
- defElmOptions :: ElmOptions
- defElmImports :: String
- data Spec :: * = Spec [String] [String]
- class ToElmType a
- specsToDir :: [Spec] -> FilePath -> IO ()
- data Proxy t :: k -> * = Proxy
Documentation
generateElmForAPI :: HasElmClient layout => Proxy layout -> [String] Source
Generate Elm code for the API with default options.
Returns a list of Elm code definitions with everything you need to query your Servant API from Elm: type definitions, JSON decoders, JSON encoders, and query functions.
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 :: HasElmClient layout => ElmOptions -> Proxy layout -> [String] Source
Generate Elm code for the API with custom options.
data ElmOptions Source
Options to configure how code is generated.
Constructors
| ElmOptions | |
Fields
| |
defElmOptions :: ElmOptions Source
The default options for generating Elm code.
urlPrefix- (An empty string)
defElmImports :: String 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.Extra exposing ((|:)) import Json.Encode import Http import String import Task
Convenience re-exports from the Elm module
class ToElmType a
specsToDir :: [Spec] -> FilePath -> IO ()
Convenience re-exports from Data.Proxy
data Proxy t :: k -> *
A concrete, poly-kinded proxy type
Constructors
| Proxy |
Instances
| Monad (Proxy *) | |
| Functor (Proxy *) | |
| Applicative (Proxy *) | |
| Foldable (Proxy *) | |
| Bounded (Proxy k s) | |
| Enum (Proxy k s) | |
| Eq (Proxy k s) | |
| Ord (Proxy k s) | |
| Read (Proxy k s) | |
| Show (Proxy k s) | |
| Ix (Proxy k s) | |
| Generic (Proxy * t) | |
| Monoid (Proxy k s) | |
| ToElmType a => ToElmType (Proxy * a) | |
| type Rep (Proxy k t) = D1 D1Proxy (C1 C1_0Proxy U1) |