This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-02-21
Channels
- # admin-announcements (3)
- # beginners (15)
- # boot (96)
- # cider (5)
- # cljsjs (2)
- # cljsrn (3)
- # clojure (22)
- # clojure-austin (2)
- # clojure-russia (16)
- # clojured (2)
- # clojurescript (65)
- # css (4)
- # cursive (89)
- # datomic (7)
- # emacs (89)
- # events (1)
- # hoplon (126)
- # leiningen (2)
- # off-topic (2)
- # om (268)
- # onyx (19)
- # parinfer (42)
- # re-frame (5)
- # reagent (30)
- # yada (8)
Hey simple question I think … I can’t seem to get my clojure ring application to decode JSON POST data into a proper map… help.
Using
[ring/ring-core "1.3.0"]
[ring/ring-devel "1.3.0"]
[ring/ring-json "0.3.1"]
[ring/ring-jetty-adapter "1.3.0"]
[ring-basic-authentication "1.0.5"]
[compojure "1.1.8”]
[compojure.route :as route]
[environ.core :refer [env]]
[ring.adapter.jetty :as jetty]
[ring.middleware.json :as json]
[ring.middleware.keyword-params :as keyword-params]
[ring.middleware.nested-params :as nested-params]
[ring.middleware.params :as params]
[ring.middleware.reload :refer :all]
[ring.middleware.session :as session]
[ring.middleware.session.cookie :as cookie]
in main:
(jetty/run-jetty (-> #'app
(keyword-params/wrap-keyword-params)
(params/wrap-params)
(json/wrap-json-params)
(json/wrap-json-body)
(json/wrap-json-response)
(handler/site {:session {:store store}})
@gavin: weed need more information on the failure and inspection of the incoming request
(at least I do)
when I send:
curl -s -X POST -H "Content-Type: application/json" -d '{"somekey" : "somevalue" }'
{:json-params {"somekey" "somevalue"},
:ssl-client-cert nil,
:cookies {},
:remote-addr "0:0:0:0:0:0:0:1",
:params {"somekey" "somevalue"},
:flash nil,
:headers
{"accept" "*/*",
"user-agent" "curl/7.30.0",
"content-type" "application/json",
"content-length" "25",
"host" "localhost:5000"},
:server-port 5000,
:content-length 25,
:form-params {},
:session/key nil,
:query-params {},
:content-type "application/json",
:character-encoding nil,
:uri "/api/mesg",
:server-name "localhost",
:query-string nil,
:body nil,
:multipart-params {},
:scheme :http,
:request-method :post,
:session {}}
@val_waeselynck: any thoughts?
For Clojure learners: an example web service leveraging boot, system, duct abstractions and components decorated with protocols has been updated to show maximum conciseness and elegance (although that is subjective): https://github.com/danielsz/system-dependency-injection