Skip to content

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

Description

@jwoudenberg

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions