servant-elm-0.1.0.2: Automatically derive Elm functions to query servant webservices.

Safe HaskellNone
LanguageHaskell2010

Servant.Elm

Contents

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"

Synopsis

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

urlPrefix :: String

The protocol, host and any path prefix to be used as the base for all requests.

Example: "https://mydomain.com/api/v1"

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

data Spec :: *

Constructors

Spec [String] [String] 

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)