我可以讀取郵寄請求的RAW JSON。但不知道我是否正確地做到了這一點?Clojure,Compojure:閱讀郵政請求RAW Json
CODE
(ns clojure-dauble-business-api.core
(:require [compojure.api.sweet :refer :all]
[ring.util.http-response :refer :all]
[clojure-dauble-business-api.logic :as logic]
[clojure.tools.logging :as log]
[clojure-dauble-business-api.domain.artwork])
(:import [clojure_dauble_business_api.domain.artwork Artwork]))
(defapi app
(GET "/hello" []
(log/info "Function begins from here")
(ok {:artwork (logic/artwork-id 10)}))
(POST "/create" params
(log/info "Create - Function begins from here and body" (:name (:artwork (:params params))))
(ok {:artwork (logic/create-city (:name (:artwork (:params params))))})))
RAW的JSON POST請求
{
"artwork": {
"id": 10,
"name": "DEFAULT"
}
}
使用這條線(:name (:artwork (:params params)))
抓取從上述原始JSON 「名稱」 的值。
如果我不是正確的方式,請指導我什麼是正確的方式?