haskell-servant / servant-elm

Automatically derive Elm functions to query servant webservices
BSD 3-Clause "New" or "Revised" License
164 stars 48 forks source link

Is it possible to use this with headers? #32

Closed eliaslfox closed 3 years ago

eliaslfox commented 6 years ago

I have several endpoints that wrap the response type with headers, such as the following,

Post '[JSON] 
    (Headers '[Header "Cache-Control" T.Text, Header "Pragma" T.Text] OauthTokenResponse)

I tried fix this with the following

instance (ElmType a) => ElmType (Headers b a) where
    toElmType = toElmType

Which compiled, but segfaulted on run.

Is this supported? Did I do something wrong?

I'm using macOS 10.12.6 And GHC version 8.0.2 with stack

eliaslfox commented 6 years ago

I'm using elm-export version 0.6.0.1 and servant-elm version 0.4.0.1

mattjbray commented 6 years ago

You were close! You need this:

instance (ElmType a) => ElmType (Headers b a) where
    toElmType = toElmType . getResponse

which is now in the latest master (b0741efc35795fb494f969c430c02987da3d7a8f).

To actually extract the response headers in the generated Elm functions will take more work, but it should at least run on your API type now.