Code Monkey home page Code Monkey logo

Comments (8)

TheOddler avatar TheOddler commented on June 7, 2024 3

Looks like in the latest version of servant.foreign (0.16 as of writing) there is now support for this, though it still just uses the generated names (which tbh I'm fine with).

Version 0.16 isn't part of any stack lts yet though, so what I did was copy this into my code:

-- Taken from https://hackage.haskell.org/package/servant-foreign-0.16/docs/src/Servant.Foreign.Internal.html#line-518
-- But that is only available on servant-foreign 0.16, which is not in any stackage lts yet
instance HasForeign lang ftype (ToServantApi r) => HasForeign lang ftype (NamedRoutes r) where
  type Foreign ftype (NamedRoutes r) = Foreign ftype (ToServantApi r)

  foreignFor lang ftype Proxy req =
    foreignFor lang ftype (Proxy :: Proxy (ToServantApi r)) req

And then updated my generateElmModuleWith ... to:

  generateElmModuleWith
    ...
    (Proxy :: Proxy (ToServantApi Web.ApiRoutes))

(Added the ToServantApi there too essentially).

from servant-elm.

TheOddler avatar TheOddler commented on June 7, 2024 1

My guess is that you're missing the mode parameter on you API? My ApiRoutes looks like this:

data ApiRoutes mode = ApiRoutes
  { ping :: mode :- "ping" :> Get '[JSON] String,
    ...
  }
  deriving (Generic)

I also have type Api = NamedRoutes ApiRoutes but that's not the one I used ToServantApi on.

from servant-elm.

blackheaven avatar blackheaven commented on June 7, 2024 1

Sorry for that, thanks a lot!

from servant-elm.

ilyakooo0 avatar ilyakooo0 commented on June 7, 2024

An obvious issue is that records fields can have duplicate names accross different modules. This would mean that we would still need to speciy the path (possibly of other names) in the names of the generated functions.

from servant-elm.

ilyakooo0 avatar ilyakooo0 commented on June 7, 2024

This is also blocked by servant-foreign not supporting this, so you should probably create an issue there.

from servant-elm.

guaraqe avatar guaraqe commented on June 7, 2024

I see, thanks, I created an issue there: haskell-servant/servant#1673

from servant-elm.

blackheaven avatar blackheaven commented on June 7, 2024

I'm not sure I get it, I have this error:

    • Expected kind ‘Type -> Type’, but ‘API’ has kind ‘Type’
    • In the first argument of ‘ToServantApi’, namely ‘API’
      In the first argument of ‘Proxy’, namely ‘(ToServantApi API)’
      In an expression type signature: Proxy (ToServantApi API)
   |
42 |     (Proxy :: Proxy (ToServantApi API))
   |                                   ^^^

Any idea what's going on?

from servant-elm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.