servant-purescript-0.9.0.2: Generate PureScript accessor functions for you servant API

Safe HaskellNone
LanguageHaskell2010

Servant.PureScript

Synopsis

Documentation

class HasBridge a where Source #

Minimal complete definition

languageBridge

defaultBridge :: BridgePart #

Default bridge for mapping primitive/common types: You can append your own bridges like this:

 defaultBridge <|> myBridge1 <|> myBridge2

Find examples for bridge definitions in Language.PureScript.Bridge.Primitives and Language.PureScript.Bridge.Tuple.

writeAPIModule :: forall bridgeSelector api. (HasForeign (PureScript bridgeSelector) PSType api, GenerateList PSType (Foreign PSType api), HasBridge bridgeSelector) => FilePath -> Proxy bridgeSelector -> Proxy api -> IO () Source #

Standard entry point - just create a purescript module with default settings for accessing the servant API.

writeAPIModuleWithSettings :: forall bridgeSelector api. (HasForeign (PureScript bridgeSelector) PSType api, GenerateList PSType (Foreign PSType api), HasBridge bridgeSelector) => Settings -> FilePath -> Proxy bridgeSelector -> Proxy api -> IO () Source #

data Settings Source #

Constructors

Settings 

Fields

  • _apiModuleName :: Text
     
  • _readerParams :: Set ParamName

    This function parameters should instead be put in a Reader monad.

    baseUrl will be put there by default, you can add additional parameters.

    If your API uses a given parameter name multiple times with different types, only the ones matching the type of the first occurrence will be put in the Reader monad, all others will still be passed as function parameter.

  • _standardImports :: ImportLines
     
  • _generateSubscriberAPI :: Bool

    If you want codegen for servant-subscriber, set this to True. See the central-counter example for a simple usage case.

addReaderParam :: ParamName -> Settings -> Settings Source #

Add a parameter name to be us put in the Reader monad instead of being passed to the generated functions.

jsonParseUrlPiece :: FromJSON a => Text -> Either Text a Source #

Use this function for implementing parseUrlPiece in your FromHttpApiData instances in order to be compatible with the generated PS code.

 
instance ToHttpApiData MyDataType where
  toUrlPiece = jsonToUrlPiece
  toHeader   = jsonToHeader

instance FromHttpApiData MyDataType where
  parseUrlPiece = jsonParseUrlPiece
  parseHeader   = jsonParseHeader

jsonToUrlPiece :: ToJSON a => a -> Text Source #

Use this function for implementing toUrlPiece in your ToHttpApiData instances in order to be compatible with the generated PS code.

jsonParseHeader :: FromJSON a => ByteString -> Either Text a Source #

Use this function for implementing parseHeader in your FromHttpApiData instances in order to be compatible with the generated PS code.

jsonToHeader :: ToJSON a => a -> ByteString Source #

Use this function for implementing toHeader in your ToHttpApiData instances in order to be compatible with the generated PS code.