2
votes

I'm trying to make a very simple API using ring in clojure. I'm using the rack.middleware.format-params middleware to convert the output to json, and the input from json to clojure data structures.

I've got the output working nicely, but I can't for the life of me access the parameters sent through json. Here's some code that works for get requests, but I can't get the POST request to return the json it recieves

(ns testing.core
  (:use [compojure.core]
        [ring.middleware.format-params :only [wrap-json-params]]
        [ring.middleware.format-response :only [wrap-json-response]]
        [ring.adapter.jetty])
  (:require [compojure.handler :as handler]))

(defroutes app-routes
  (GET "/"
       []
       {:body {:hello "world"}})

  (POST "/"
        {params :params}
        {:body params}))

(def app
  (-> (handler/api app-routes)
      (wrap-json-params)
      (wrap-json-response)))

It just returns this: {}

What am I doing wrong?

1

1 Answers

6
votes

I'm an idiot and realised that I wasn't sending the json Content-Type header. Hopefully no-one else makes the same silly mistake :P