This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-19
Channels
- # announcements (13)
- # asami (43)
- # babashka (35)
- # beginners (175)
- # calva (23)
- # cider (5)
- # clj-kondo (68)
- # cljsrn (4)
- # clojure (61)
- # clojure-australia (7)
- # clojure-europe (20)
- # clojure-gamedev (59)
- # clojure-israel (11)
- # clojure-italy (4)
- # clojure-nl (2)
- # clojure-norway (21)
- # clojure-spec (12)
- # clojure-uk (43)
- # clojurescript (9)
- # cursive (56)
- # data-oriented-programming (5)
- # datascript (1)
- # events (1)
- # fulcro (16)
- # honeysql (46)
- # leiningen (1)
- # malli (4)
- # off-topic (12)
- # pathom (46)
- # re-frame (24)
- # reagent (14)
- # reitit (1)
- # reveal (8)
- # rewrite-clj (16)
- # ring (13)
- # sci (9)
- # spacemacs (14)
- # specter (2)
- # sql (2)
- # tools-deps (1)
- # vim (2)
I am trying to create my first ring/compojure application and seem to hit a wall. I am returning a simple JSON response and the app seems to always return with the incorrect content type.
(ns clojure-rest-server.handler
(:require [compojure.core :refer :all]
[compojure.route :as route]
[ring.util.response :refer [response]]
[clojure.pprint]
[ring.handler.dump :refer [handle-dump]]
[ring.middleware.json :refer [wrap-json-response wrap-json-body]]
[ring.middleware.defaults :refer [wrap-defaults api-defaults]]))
(defroutes app-routes
(POST "/" {body :body} (response {:msg "hello-world"}))
(route/not-found "Not Found"))
(def app
(-> (wrap-defaults app-routes api-defaults)
(wrap-json-body)
(wrap-json-response)))
When i do a curl or use postman i allays get a
$ curl -i --header "Content-Type: application/json" \
--request POST \
HTTP/1.1 200 OK
Date: Fri, 19 Feb 2021 13:30:50 GMT
Content-Type: application/octet-stream
Transfer-Encoding: chunked
Server: Jetty(9.2.21.v20170120)
{"msg":"hello-world"}%
Any hint what i am doing wrong?@marco.pasopas here's what I've done. it's quite simple. I am no means a user of compojure, but I hope it helps: https://github.com/dharrigan/ring-json
@dharrigan Many thanks!! It seems to work now indeed with your help.
That whole middleware stuff is a bit confusing. Every demo on the internet more or less make the same mistake. The content type is not taken into account