servant-purescript 0.3.1.5 → 0.4.0.0
raw patch · 4 files changed
+18/−4 lines, 4 files
Files
- Readme.md +10/−1
- servant-purescript.cabal +1/−1
- src/Servant/PureScript.hs +4/−0
- src/Servant/PureScript/CodeGen.hs +3/−2
Readme.md view
@@ -13,7 +13,16 @@ [purescript-argonaut-generic-codecs](https://github.com/eskimor/purescript-argonaut-generic-codecs/blob/purescript-argonaut-generic-codec/src/Data/Argonaut/Generic/Aeson.purs). - You can put common parameters like Auth tokens and the base URL in a reader monad so you don't have to pass them explicitly. This is configurable in the code generator with `readerParams` in `Settings`.+ +## Usage +Apart from the above basic usage example the documentation is still lacking. For+the purescript side make sure you have+[purescript-servant-support](https://github.com/eskimor/purescript-servant-support)+and+[purescript-argonaut-generic-codecs](https://github.com/eskimor/purescript-argonaut-generic-codecs)+installed, otherwise the generated code will not compile.+ ## Status It works!@@ -21,6 +30,6 @@ Documentation is yet to come, but there is a usage example in examples/central-counter which also uses servant-subscriber used for counter live updates. Generated code is only partly tested, especially Query parameters-are completely untested.+are still completely untested. For type translations purescript-bridge is used.
servant-purescript.cabal view
@@ -1,5 +1,5 @@ name: servant-purescript-version: 0.3.1.5+version: 0.4.0.0 synopsis: Generate PureScript accessor functions for you servant API description: Please see README.md homepage: https://github.com/eskimor/servant-purescript#readme
src/Servant/PureScript.hs view
@@ -38,6 +38,7 @@ import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.Encoding as T+import qualified Data.Text.IO as T import Language.PureScript.Bridge import Network.HTTP.Types (urlDecode, urlEncode) import Servant.Foreign@@ -69,6 +70,9 @@ when (opts ^. generateSubscriberAPI) $ do writeModule (opts ^. apiModuleName <> ".Subscriber") SubGen.genModule writeModule (opts ^. apiModuleName <> ".MakeRequests") MakeRequests.genModule+ T.putStrLn "Successfully created your servant API purescript functions!"+ T.putStrLn "Please make sure you have purescript-servant-support version 2.0.0 or above installed:\n"+ T.putStrLn " bower i --save purescript-servant-support\n" where apiList = apiToList pAPI pBr
src/Servant/PureScript/CodeGen.hs view
@@ -115,7 +115,7 @@ </> hang 6 ("let httpMethod =" <+> dquotes (req ^. reqMethod ^. to T.decodeUtf8 ^. to strictText)) </> hang 6 ("let reqUrl =" <+> genBuildURL (req ^. reqUrl)) </> "let reqHeaders =" </> indent 6 (req ^. reqHeaders ^. to genBuildHeaders)- </> "affResp <- liftAff $ affjax " <> hang 2 ( "defaultRequest" </>+ </> "let affReq =" <+> hang 2 ( "defaultRequest" </> "{ method =" <+> "httpMethod" </> ", url =" <+> "reqUrl" </> ", headers =" <+> "defaultRequest.headers <> reqHeaders"@@ -123,7 +123,8 @@ Nothing -> "}" Just _ -> ", content =" <+> "toNullable <<< Just <<< printJson <<< encodeJson $ reqBody" </> "}" )- </> "getResult decodeJson affResp" <> line+ </> "affResp <- liftAff $ affjax affReq"+ </> "getResult affReq decodeJson affResp" <> line ) genBuildURL :: Url PSType -> Doc