dakrone / clj-http

An idiomatic clojure http client wrapping the apache client. Officially supported version.
http://clojars.org/clj-http
MIT License
1.77k stars 408 forks source link

`with-middleware` rebinds `http/request` with new core client #644

Open SevereOverfl0w opened 4 months ago

SevereOverfl0w commented 4 months ago

If you have a function like this:

(defn make-request
  [request]
  (http/with-additional-middleware [...]
    (http/request request))) 

And you call it with mocking, like so:

(binding [http/request (http/make-request (constantly {:status 201}))]
  (make-request {...}))

Then the default client (clj-http.core/request) will be used instead of (constantly {:status 201}). This is due to with-middleware rebinding http/request itself