Hello everyone,
I’m picked up coding as a hobby a few years ago, I can do stuff but a lot of CS/SE concepts are unfamiliar to me. And I think this is one of those cases where this lack of knowledge is slowing me down a bit.
I’m building my first web app using clojure/clojurescript for backend/frontend and I just can’t make it work. The backend looks like this:
(ns example.handler
(:require [compojure.core :refer :all]
[compojure.route :as route]
[clojure.data.json :as json]
[clj-http.client :as client]
[datomic.api :as d]
[ring.util.response :as resp]
[ring.middleware.defaults :refer [wrap-defaults site-defaults]])
(:use [hiccup.core]))
;; Route
(defroutes app-routes
(GET "/info" [] (json/write-str {:data (some-function x)})))
Everything is fine up to this point, when I go to localhost:3000/info
I see on the browser something like {"data":10}
which is the expected result
The issue is when I try to get this data from clojurescript, here’s the code:
(ns example-cljs.core
(:require [reagent.core :as reagent :refer [atom]]
[clojure.core.async :as async]
[cljs-http.client :as http]))
(def example-req (atom nil))
(defn get-data []
(async/go
(let [response (async/<! (http/get "localhost:3000/info"))]
(reset! example-req response))))
which is basically the example from cljs-http documentation, but what I get is this: {:status 0, :success true, :body "", :headers {}, :trace-redirects ["localhost:3000/info" "localhost:3000/info"], :error-code :no-error, :error-text ""}
I have no idea of what is going on and it’s driving me insane. Any help or hints in the right direction will be great.
Thanks.