|
11 | 11 | {-# LANGUAGE CPP #-}
|
12 | 12 | {-# LANGUAGE RecordWildCards #-}
|
13 | 13 | {-# LANGUAGE TemplateHaskell #-}
|
| 14 | +{-# LANGUAGE UndecidableInstances #-} |
| 15 | +{-# LANGUAGE FlexibleContexts #-} |
14 | 16 | -----------------------------------------------------------------------------
|
15 | 17 | -- |
|
16 | 18 | -- Module : Miso.Fetch
|
@@ -64,6 +66,7 @@ import Data.Proxy (Proxy(..))
|
64 | 66 | import GHC.TypeLits
|
65 | 67 | import Language.Javascript.JSaddle (JSM)
|
66 | 68 | import Servant.API
|
| 69 | +import Servant.API.Modifiers |
67 | 70 | -----------------------------------------------------------------------------
|
68 | 71 | import Miso.FFI.Internal (fetchJSON)
|
69 | 72 | import Miso.Lens
|
@@ -130,19 +133,25 @@ instance (Fetch api, KnownSymbol path) => Fetch (path :> api) where
|
130 | 133 | options_ :: FetchOptions
|
131 | 134 | options_ = options & currentPath %~ (<> ms "/" <> path)
|
132 | 135 | -----------------------------------------------------------------------------
|
133 |
| -instance (Show a, Fetch api, KnownSymbol path) => Fetch (Capture path a :> api) where |
| 136 | +instance (ToHttpApiData a, Fetch api, KnownSymbol path) => Fetch (Capture path a :> api) where |
134 | 137 | type ToFetch (Capture path a :> api) = a -> ToFetch api
|
135 | 138 | fetchWith Proxy options arg = fetchWith (Proxy @api) options_
|
136 | 139 | where
|
137 | 140 | options_ :: FetchOptions
|
138 |
| - options_ = options & currentPath %~ (<> ms "/" <> ms (show arg)) |
| 141 | + options_ = options & currentPath %~ (<> ms "/" <> ms (toEncodedUrlPiece arg)) |
139 | 142 | -----------------------------------------------------------------------------
|
140 |
| -instance (Show a, Fetch api, KnownSymbol name) => Fetch (QueryParam name a :> api) where |
141 |
| - type ToFetch (QueryParam name a :> api) = a -> ToFetch api |
| 143 | +instance (ToHttpApiData a, Fetch api, SBoolI (FoldRequired mods), KnownSymbol name) => Fetch (QueryParam' mods name a :> api) where |
| 144 | + type ToFetch (QueryParam' mods name a :> api) = RequiredArgument mods a -> ToFetch api |
142 | 145 | fetchWith Proxy options arg = fetchWith (Proxy @api) options_
|
143 | 146 | where
|
| 147 | + param (x :: a) = [(ms "/", ms (enc x))] |
| 148 | +#if MIN_VERSION_http_api_data(0,5,1) |
| 149 | + enc = toEncodedQueryParam |
| 150 | +#else |
| 151 | + enc = toEncodedUrlPiece |
| 152 | +#endif |
144 | 153 | options_ :: FetchOptions
|
145 |
| - options_ = options & queryParams <>~ [(ms "/", ms (show arg))] |
| 154 | + options_ = options & queryParams <>~ foldRequiredArgument (Proxy @mods) param (foldMap param) arg |
146 | 155 | -----------------------------------------------------------------------------
|
147 | 156 | instance (Fetch api, KnownSymbol name) => Fetch (QueryFlag name :> api) where
|
148 | 157 | type ToFetch (QueryFlag name :> api) = Bool -> ToFetch api
|
|
0 commit comments