servant-to-elm 0.1.0.0 → 0.2.0.0
raw patch · 5 files changed
+33/−27 lines, 5 filesdep ~haskell-to-elmPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: haskell-to-elm
API changes (from Hackage documentation)
- Servant.To.Elm: instance Language.Haskell.To.Elm.HasElmDefinition Servant.API.ContentTypes.NoContent
Files
- CHANGELOG.md +4/−0
- README.md +15/−1
- examples/UserAPI.hs +7/−15
- servant-to-elm.cabal +5/−5
- src/Servant/To/Elm.hs +2/−6
CHANGELOG.md view
@@ -2,6 +2,10 @@ ## Unreleased changes +## 0.2.0.0++- Update code with changes from `haskell-to-elm-0.2.0.0`+ ## 0.1.0.0 - Initial release
README.md view
@@ -1,4 +1,4 @@-# servant-to-elm+# servant-to-elm [](https://hackage.haskell.org/package/servant-to-elm) This is a library for generating Elm client libraries from Servant API definitions.@@ -128,6 +128,20 @@ In an actual project we would be writing the code to disk instead of printing it. See [this file](examples/UserAPI.hs) for the full code with imports.++## Auth-protected routes++If you use `AuthProtect` from `Servant.API.Experimental.Auth`, the following+code can be used:++```haskell+instance HasElmEndpoints api => HasElmEndpoints (AuthProtect "auth" :> api) where+ elmEndpoints' = elmEndpoints' @(Header' '[ Required, Strict] "Authorization" Token :> api)+```++This makes endpoints under `AuthProtect "auth"` take an extra `Token` parameter+which are added as authorization headers to the requests. This assumes that+`Token` has appropriate instances for `HasElmType` and `HasElmEncoder Text`. ## Related projects
examples/UserAPI.hs view
@@ -22,27 +22,19 @@ data User = User { name :: Text , age :: Int- } deriving- ( Generic- , Aeson.ToJSON- , SOP.Generic- , SOP.HasDatatypeInfo- , HasElmDecoder Aeson.Value- , HasElmEncoder Aeson.Value- , HasElmType- )+ } deriving (Generic, Aeson.ToJSON, SOP.Generic, SOP.HasDatatypeInfo) -instance HasElmDefinition User where+instance HasElmType User where elmDefinition =- deriveElmTypeDefinition @User defaultOptions "Api.User.User"+ Just $ deriveElmTypeDefinition @User defaultOptions "Api.User.User" -instance HasElmDecoderDefinition Aeson.Value User where+instance HasElmDecoder Aeson.Value User where elmDecoderDefinition =- deriveElmJSONDecoder @User defaultOptions Aeson.defaultOptions "Api.User.decoder"+ Just $ deriveElmJSONDecoder @User defaultOptions Aeson.defaultOptions "Api.User.decoder" -instance HasElmEncoderDefinition Aeson.Value User where+instance HasElmEncoder Aeson.Value User where elmEncoderDefinition =- deriveElmJSONEncoder @User defaultOptions Aeson.defaultOptions "Api.User.encoder"+ Just $ deriveElmJSONEncoder @User defaultOptions Aeson.defaultOptions "Api.User.encoder" type UserAPI = "user" :> Get '[JSON] User
servant-to-elm.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: a72d33a5b5a0f94d44e7e4e23970669fe65894da52c59170b08a0c87725c898e+-- hash: 11605446602bdfe9cebe8697f26a8560fb1d2b9ff791eaf13b847658631ffb92 name: servant-to-elm-version: 0.1.0.0+version: 0.2.0.0 synopsis: Automatically generate Elm clients for Servant APIs description: Please see the README on GitHub at <https://github.com/folq/servant-to-elm#readme> category: Servant, API, Elm, Compiler@@ -45,7 +45,7 @@ , base >=4.7 && <5 , bound >=2.0.0 , elm-syntax >=0.1.0 && <0.1.1- , haskell-to-elm >=0.1.0 && <0.1.1+ , haskell-to-elm >=0.2.0 && <0.2.1 , http-types >=0.12.0 , protolude >=0.2.3 , servant >=0.16.0@@ -65,7 +65,7 @@ , bound >=2.0.0 , elm-syntax >=0.1.0 && <0.1.1 , generics-sop- , haskell-to-elm >=0.1.0 && <0.1.1+ , haskell-to-elm >=0.2.0 && <0.2.1 , http-types >=0.12.0 , protolude >=0.2.3 , servant@@ -89,7 +89,7 @@ , base >=4.7 && <5 , bound >=2.0.0 , elm-syntax >=0.1.0 && <0.1.1- , haskell-to-elm >=0.1.0 && <0.1.1+ , haskell-to-elm >=0.2.0 && <0.2.1 , http-types >=0.12.0 , protolude >=0.2.3 , servant >=0.16.0
src/Servant/To/Elm.hs view
@@ -600,13 +600,9 @@ ------------------------------------------------------------------------------- -- Orphans -instance HasElmDefinition Servant.NoContent where- elmDefinition =- Definition.Type "NoContent.NoContent" [("NoContent", [])]- instance HasElmType Servant.NoContent where- elmType =- "NoContent.NoContent"+ elmDefinition =+ Just $ Definition.Type "NoContent.NoContent" [("NoContent", [])] instance HasElmDecoder Aeson.Value Servant.NoContent where elmDecoder =