clj-http-fake
clj-http-fake copied to clipboard
Supporting async requests from clj-http.
Hi! Would be nice to add support for async requests from clj-http. It requires some additions to the API that could be a bit challenging but still useful in asynchronous scenarios. In my use-case it can improve things a lot in terms of tests backward-compatibility while moving certain parts of the application to clj-http/3.x and async requests.
Hi. You can make a pull request for this :) I haven't touched anything clojure related in years.
@dixel did you find a workaround for this? I’m looking for a solution to mock async requests for clj-http
.
@bfontaine not really. So far with-redefs does quite a good job most of the time.
Unless I’m missing something, if you use the response
/raise
callbacks, using clj-http-fake
with :async?
requests is perfectly fine:
(with-fake-routes-in-isolation {"http://foo" (fn [_] {:status 201 :headers {}})}
(http/get "http://foo"
{:async? true}
(fn [a] (println "OK" a))
(fn [b] (println "NOPE" b))))
;; prints:
;; OK {:status 200, :body , :headers {}, :request-time 0, :orig-content-encoding nil}
It doesn’t work only if you rely on the FutureWrapper
returned by clj-http.
I ran into this issue the other day. Since this has been pending for a while I wrote up a PR and submitted it for review.
I ran into this issue the other day. Since this has been pending for a while I wrote up a PR and submitted it for review.
Would it be possible to build a new release that contains this fix?
Yeah.. um, would you like to do it? :) I don't feel like installing the whole clojure stuff just for this, but I probably can add you as a collaborator here and on clojars