ring

fabrao 2017-05-16T16:37:55.716465Z

Hello all, is there any way to do async response of a route?

fabrao 2017-05-16T16:39:38.746671Z

(GET "/login" {params :params} (valid-login (params :username) (params :password)))
-> calls an ajax request and handles async response

fabrao 2017-05-16T16:40:00.753268Z

how to handle with that?

fabrao 2017-05-16T16:40:50.768207Z

(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"})
    })
  )

2017-05-16T17:13:04.350560Z

@fabrao Yes, you return a three-argument handler, like:

2017-05-16T17:13:54.364935Z

(GET "/login" [username password]
  (fn [_ respond _]
    (respond (valid-login username password))))

2017-05-16T17:14:09.369459Z

That’s using respond synchronously, but you can pass it as a callback.

2017-05-16T17:14:35.376964Z

Or extend the compojure.response/Sendable protocol for channels or some other asynchronous abstraction.

fabrao 2017-05-16T17:18:20.443179Z

@weavejester I tested it but it´s getting "class ajax.apache$to_clojure_future$reify__72385 is not understandable"

2017-05-16T17:19:46.467613Z

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?

fabrao 2017-05-16T17:20:50.486640Z

[ring/ring-defaults "0.2.1"] [ring/ring-json "0.5.0-beta1"] [buddy/buddy-auth "1.4.1"] [compojure "1.5.0"]

fabrao 2017-05-16T17:22:22.514493Z

how do I set :async?

2017-05-16T17:22:51.523098Z

You need to upgrade your dependencies, and you need to set :async? true to your Jetty adapter.

fabrao 2017-05-16T17:24:00.543503Z

I´m using figwheel ring handler

fabrao 2017-05-16T17:24:43.555775Z

is that possible to set :async? true to ring-handler?

2017-05-16T17:25:05.562342Z

Not sure. It might be an option. Take a look through the docs.

2017-05-16T17:25:20.566864Z

I need to go. bbl