Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

newtype encoding for query param does not match decoding by Servant #35

Open
jwoudenberg opened this issue Nov 30, 2017 · 0 comments
Open

Comments

@jwoudenberg
Copy link

jwoudenberg commented Nov 30, 2017

First of all, thank you for your work in creating this library!

I've hit a small snag: I have a newtype that is used as a capture parameter in an endpoint:

newtype Id = Id Int32 deriving ( Eq, Generic, Show, FromHttpApiData)

type API = Capture "id" Id :> ReqBody '[ JSON] Resource :> Put '[ JSON] NoContent

The generated API function generates a URL that looks like this: /Id%206, because it whereas servant's default decoder for this newtype expects a URL that simply reads /6. It looks like this happens when the Elm version of the newtype (type Id = Id Int) is passed through toString.

Is there something I can do to make this work, short of getting rid of getting rid of the newtype?

One potential avenue: We also generate an elm encodeId : Int -> Json.Encode.Value function. If for encoding the parameter in the query string we'd call that function first, then encode the Json value into a string it looks like we would generate the correct URI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant