servant
servant copied to clipboard
UTCTime in url results in 'not found' error
I have this route:
type RoutesCMS =
Capture "system" SystemLang
:> Capture "lang" TextLang
:> Capture "pagename" Text
:> Capture "time" UTCTime
:> Get '[JSON] [Pandoc]
Just once I added Capture "time" UTCTime
, I get a not found error for my api:
No handler accepted "/api/cms/SystemDE/EN/Stage1-1_Type-the-letters/1859-02-25T00%3A16%3A40Z"
I changed UTCTime
to a newtype with custom instances for FromHttpApiData
and ToHttpApiData
like this:
newtype UTCTimeInUrl = UTCTimeInUrl { unUTCTimeInUrl :: UTCTime }
instance ToHttpApiData UTCTimeInUrl where
toUrlPiece = Text.replace ":" "_" . toUrlPiece . unUTCTimeInUrl
instance FromHttpApiData UTCTimeInUrl where
parseUrlPiece = fmap UTCTimeInUrl . parseUrlPiece . Text.replace "_" ":"
and the problem vanishes. So there seems to be a problem with the url encoding of ":".
I am using Servant 0.19.1
and http-api-data 0.4.2
(the newest version is 0.5). I am unsure whether or not this issue belongs to the repo of http-api-data
. I don't know where the url encoding happens.
how is your URL getting encoded? the URL that successfully gets captured is /api/cms/SystemDE/EN/Stage1-1_Type-the-letters/1859-02-25T00:16:40Z
(i.e. without the %3As). http-api-data-0.5
has some adjustments to how years with less than four digits are parsed, but this shouldn't make a difference in your case
Oh I see. The ":" shouldn't be url encoded in the first place. So probably this is a bug with servant-reflex
(which I use to generate my client). I will check there ...
@rubenmoor Can we close this ticket on our end? Is this something that servant can still act on?
please close, definitely a problem specific to servant-reflex