Denis
Denis

Reputation: 1543

response map is nil compojure

I just don't understand anything. When I do curl -X GET --header 'Accept: application/json' 'http://localhost:3000/api/hello' from my swagger I get a nice answer {"result":1}. However, when I try something like: http://localhost:3000/api/hello?criteria=drf, the server gives me java.lang.NullPointerException: Response map is nil. I am pretty sure it's not nil, since I still get my {"result":1} back on the screen. But after that first error, every GET /hello request, without any query parameters, gives an error on server side, while still giving the right answer to the client?

And I need to restart server in order to make the error stop. Which works, until the first request with query params....

(ns swag.handler
  (:require [compojure.api.sweet :refer :all]
            [ring.util.http-response :refer :all]
            [clojure.java.jdbc :as j]
            [clojure.core.match :as match]
            [clojure.spec.alpha :s s]
            )
(def app
  (api
    {:swagger
     {:ui "/"
      :spec "/swagger.json"
      :data {:info {:title "Trash"
                    :description "Compojure Api example"}
             :tags [{:name "api", :description "some apis"}]}}}

    (context "/api" []
      :tags ["api"]

      (GET "/plus" []
        :return {:result Long}
        :query-params [x :- Long, y :- Long]
        :summary "adds two numbers together"
        (ok {:result (+ x y)}))

      (GET "/hello" []
        :query-params [& z]
        (let [criteria (:criteria z) values (:date z)]
          (println z)
          (ok {:result 1})))
))
  )

Upvotes: 2

Views: 2892

Answers (2)

Ricardo Mayerhofer
Ricardo Mayerhofer

Reputation: 2309

If you're getting this message, check for favicon.ico request in the browser.

This may trigger a response map is null because no route is configured to handle it.

Upvotes: 3

BWStearns
BWStearns

Reputation: 2706

Issue for us was we needed trailing /s on the endpoint that was giving us this error (was looking at your q while we were debugging, but just solved).

Upvotes: 0

Related Questions