Clojure and Python Flask

59 views
Skip to first unread message

Pascal Dutilleul

unread,
Jan 9, 2021, 9:32:51 AM1/9/21
to Clojure

Does somebody has experience serving ClojureScript (Re-Frame) through Python Flask? Or even better integrating a Clojure app within an existing Flask app ? I need to add a new module to an existing Flask app and I’d like at least the frontend to be ClojureScript. What are the possibilities?

Kind regards,
Pascal

alexandr...@gmail.com

unread,
Jan 9, 2021, 3:27:38 PM1/9/21
to Clojure
This shouldn't be a problem - you can send all Flask responses as JSON and it will work fine in CLJS.


In Clojurescript, use for instance https://github.com/r0man/cljs-http to read the JSON responses.

So something like this in your cljs:

(defn http-get-dispatch [request]
(go (let [response (<! (http/get (:url request)))]
(rf/dispatch (conj (:dispatch-key request) (:body response))))))

(rf/reg-fx :http-get-dispatch http-get-dispatch)

(rf/reg-event-fx
:your-request
(fn [{:keys [db]} [_ x1 x2]] 
{:http-get-dispatch {:url (str "your-server-url?x1=" x1 "&x2=" x2)
:dispatch-key [:your-client-db-key]}}))

(rf/reg-event-db
:your-client-db-key
(fn [db [_ data]] (assoc db :your-client-db-key data)))
Reply all
Reply to author
Forward
0 new messages