【发布时间】:2018-02-28 03:46:59
【问题描述】:
我什么都不懂。
当我大摇大摆地做curl -X GET --header 'Accept: application/json' 'http://localhost:3000/api/hello' 时,我得到了一个很好的答案{"result":1}。
但是,当我尝试类似:http://localhost:3000/api/hello?criteria=drf 时,服务器会给我java.lang.NullPointerException: Response map is nil。我很确定它不是零,因为我的{"result":1} 仍然出现在屏幕上。
但是在第一个错误之后,每个GET /hello 请求,没有任何查询参数,在服务器端给出一个错误,同时仍然给客户端正确的答案?
并且我需要重新启动服务器才能使错误停止。哪个有效,直到第一个带有查询参数的请求......
(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})))
))
)
【问题讨论】:
-
不会为“/hello”添加 GET?解决问题?似乎服务器已经崩溃,因此变得无响应,但浏览器仍在以某种方式通过其缓存做出响应。
-
我无法在 compojure-api 示例中使用您的 def 重现此错误:github.com/metosin/compojure-api/tree/master/examples/simple。带参数的 Get 有效。