Hello all, is there any way to do async response of a route?
(GET "/login" {params :params} (valid-login (params :username) (params :password)))
-> calls an ajax request and handles async responsehow to handle with that?
(defn valid-login [usuario senha]
(ajax/ajax-request
{:uri "https://******/login?$format=JSON"
:method :post
:params {:username usuario
:password senha}
:format (ajax/url-request-format)
:response-format (ajax/json-response-format {:keywords? true})
:error-handler #(response {:resposta "OK"})
:handler #(response {:resposta "OK"})
})
)
@fabrao Yes, you return a three-argument handler, like:
(GET "/login" [username password]
(fn [_ respond _]
(respond (valid-login username password))))
That’s using respond
synchronously, but you can pass it as a callback.
Or extend the compojure.response/Sendable
protocol for channels or some other asynchronous abstraction.
@weavejester I tested it but it´s getting "class ajax.apache$to_clojure_future$reify__72385 is not understandable"
Do you have the :async?
option set on the adapter? Are you using Compojure 1.6.0 and Ring 1.6.1? Are you trying to return some kind of custom async object?
[ring/ring-defaults "0.2.1"] [ring/ring-json "0.5.0-beta1"] [buddy/buddy-auth "1.4.1"] [compojure "1.5.0"]
how do I set :async?
You need to upgrade your dependencies, and you need to set :async? true
to your Jetty adapter.
I´m using figwheel ring handler
is that possible to set :async? true
to ring-handler?
Not sure. It might be an option. Take a look through the docs.
I need to go. bbl