Created
September 1, 2015 18:51
-
-
Save not-much-io/764c5bb5b46c804b6a42 to your computer and use it in GitHub Desktop.
Problem with POST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;cljs-ajax POST | |
(defn handler [[ok response]] | |
(.log js/console "Client handling response!") | |
(if ok | |
(.log js/console (str "Response: " response)) | |
(.error js/console (str "Errora: " response)))) | |
(defn send-msg [data] | |
(.log js/console "Client sending request!") | |
(POST "/add-scroll" | |
{:params {:message "Hello World" | |
:user "not-much"} | |
:handler handler | |
:error-handler handler})) | |
;;handler.clj | |
(defn example-server-handler [{:keys [params]}] | |
(println "Handling Request!") | |
(println params) | |
(response {:status :success})) | |
(defroutes routes | |
(GET "/" [] home-page) | |
(POST "/add-scroll" request | |
(do | |
(println "Server Recieved Request!") | |
(println request) | |
(example-server-handler request))) | |
(resources "/") | |
(not-found "Not Found")) | |
(def app | |
(let [site-conf (assoc-in site-defaults [:security :anti-forgery] false) | |
handler (wrap-defaults #'routes site-conf)] | |
(if (env :dev) (-> handler wrap-exceptions wrap-reload wrap-params) handler))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
Client sending request!
Server Recieved Request!
{:cookies {ring-session {:value 8af1c042-e25c-4cd9-9324-4123634285be}}, :remote-addr 127.0.0.1, :params {}, :flash nil, :route-params {}, :headers {origin http://localhost:3449, host localhost:3449, user-agent Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36, content-type application/transit+json; charset=UTF-8, cookie ring-session=8af1c042-e25c-4cd9-9324-4123634285be, content-length 52, referer http://localhost:3449/?, connection keep-alive, pragma no-cache, accept application/json, application/edn, application/transit+json, text/plain, text/html, /, accept-language et,en-GB;q=0.8,en;q=0.6, accept-encoding gzip, deflate, dnt 1, cache-control no-cache}, :async-channel #object[org.httpkit.server.AsyncChannel 0x42bb0f12 /127.0.0.1:3449<->/127.0.0.1:35225], :server-port 3449, :content-length 52, :form-params {}, :compojure/route [:post /add-scroll], :websocket? false, :session/key nil, :query-params {}, :content-type application/transit+json, :character-encoding UTF-8, :uri /add-scroll, :server-name localhost, :query-string nil, :body #object[org.httpkit.BytesInputStream 0x60b270d7 BytesInputStream[len=52]], :multipart-params {}, :scheme :http, :request-method :post, :session {}}
Handling Request!
{}
Client handling response!
Response: :