Skip to content

Commit 4cdbbbd

Browse files
authored
Make defaultMakeClientRequest not depend on IO (#1789)
The `IO` wrap for the return type of this function was never necessary. Inside the function there’s only `return` call that wraps a _pure_ value into `IO`. There is nothing else that would be related to `IO`. The `IO` wrap was introduced in 9df16f9 In order to not break the API again the wrap was preserved but this change makes it to depend on any `Applicative` instead of `IO`. So it still works in `IO`/`MonadIO` context but allows to use something like `Data.Functor.Identity` to work with _pure_ values. See for more context: #1595
1 parent d7185da commit 4cdbbbd

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

servant-client/src/Servant/Client/Internal/HttpClient.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,15 @@ clientResponseToResponse f r = Response
232232
-- | Create a @http-client@ 'Client.Request' from a @servant@ 'Request'
233233
-- The 'Client.host', 'Client.path' and 'Client.port' fields are extracted from the 'BaseUrl'
234234
-- otherwise the body, headers and query string are derived from the @servant@ 'Request'
235-
defaultMakeClientRequest :: BaseUrl -> Request -> IO Client.Request
236-
defaultMakeClientRequest burl r = return Client.defaultRequest
235+
--
236+
-- Note that @Applicative@ dependency is not really needed for this function
237+
-- implementation. But in the past the return type was wrapped into @IO@
238+
-- without a necessity breaking the API backward-compatibility. In order to not
239+
-- break the API again it was changed to @Applicative@ so that you can just use
240+
-- something like @Data.Functor.Identity@ without a need to involve @IO@ but
241+
-- still keeping it compatible with the code written when it was typed as @IO@.
242+
defaultMakeClientRequest :: Applicative f => BaseUrl -> Request -> f Client.Request
243+
defaultMakeClientRequest burl r = pure Client.defaultRequest
237244
{ Client.method = requestMethod r
238245
, Client.host = fromString $ baseUrlHost burl
239246
, Client.port = baseUrlPort burl

0 commit comments

Comments
 (0)