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://localhost:3000>
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?Oh I see you are here already
I hope my posting in #beginners helps
@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.
Found an old issue that more or less dscribes this
very good
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
I should read the manual 🙂
I don't use compojure myself, I prefer #reitit (which uses ring underneath, as the's sorta the defacto standard)
I am hit by the middleware from ring and not so much by compojure, retit will be my next thiing on the todo list 🙂