My web client (written in cljs
) connects to backend (written in clj
) which needs to make a few third party API calls. It has to be done on the server and then the result should be transformed in a specific way and sent back to the client.
Here's my handler for one of the urls
(defn get-orders [req]
(let [{:keys [sig uri]} (api-signature :get-orders)]
(client/get uri
{:async? true}
(fn [response] {:body "something"})
(fn [exception] {:body "error"}))))
Instead of returning {:body "something"}
, it is returning the following error:
No implementation of method: :render of protocol: #'compojure.response/Renderable found for class: org.apache.http.impl.nio.client.FutureWrapper
What am I doing wrong?
When you specify
{:async? true}
,clj-http.client/get
will return a future which is aFutureWrapper
in the error message you got.So if you don't need async, don't use it. This is an example of a synchronous ring handler which calls a third-party url and returns the response that got back.
If you really need async, use async version of ring handler.
Don't forget to config webserver adapter to use the async handler. For example, for Jetty, set
:async?
flag totrue
like soIf you want to concurrently call to multiple third-party urls and return once to web client, use promise to help