Skip to content

Commit f84d053

Browse files
committed
Fix Servant parameter encoding
The CPP is necessary, since `toUrlPiece` is incorrect, but we're tied to an old `http-api-data` on GHCJS. See fizruk/http-api-data#120.
1 parent 4fcce33 commit f84d053

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/Miso/Fetch.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,24 @@ instance (Fetch api, KnownSymbol path) => Fetch (path :> api) where
130130
options_ :: FetchOptions
131131
options_ = options & currentPath %~ (<> ms "/" <> path)
132132
-----------------------------------------------------------------------------
133-
instance (Show a, Fetch api, KnownSymbol path) => Fetch (Capture path a :> api) where
133+
instance (ToHttpApiData a, Fetch api, KnownSymbol path) => Fetch (Capture path a :> api) where
134134
type ToFetch (Capture path a :> api) = a -> ToFetch api
135135
fetchWith Proxy options arg = fetchWith (Proxy @api) options_
136136
where
137137
options_ :: FetchOptions
138-
options_ = options & currentPath %~ (<> ms "/" <> ms (show arg))
138+
options_ = options & currentPath %~ (<> ms "/" <> ms (toEncodedUrlPiece arg))
139139
-----------------------------------------------------------------------------
140-
instance (Show a, Fetch api, KnownSymbol name) => Fetch (QueryParam name a :> api) where
140+
instance (ToHttpApiData a, Fetch api, KnownSymbol name) => Fetch (QueryParam name a :> api) where
141141
type ToFetch (QueryParam name a :> api) = a -> ToFetch api
142142
fetchWith Proxy options arg = fetchWith (Proxy @api) options_
143143
where
144+
#if MIN_VERSION_http_api_data(0,5,1)
145+
enc = toEncodedQueryParam
146+
#else
147+
enc = toEncodedUrlPiece
148+
#endif
144149
options_ :: FetchOptions
145-
options_ = options & queryParams <>~ [(ms "/", ms (show arg))]
150+
options_ = options & queryParams <>~ [(ms "/", ms (enc arg))]
146151
-----------------------------------------------------------------------------
147152
instance (Fetch api, KnownSymbol name) => Fetch (QueryFlag name :> api) where
148153
type ToFetch (QueryFlag name :> api) = Bool -> ToFetch api

0 commit comments

Comments
 (0)