Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transact action should support common encoding formats- JSON, Transit, edn, and Form-POST #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/com/cognitect/vase/actions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,22 @@
(defn merged-parameters
[request]
{:post [(map? %)]}
(let [{:keys [path-params params json-params edn-params]} request]
(merge (if (empty? path-params) {} (decode-map path-params)) params json-params edn-params)))
(let [{:keys [path-params params json-params transit-params edn-params]} request]
(merge (if (empty? path-params) {} (decode-map path-params))
params
json-params
transit-params
edn-params)))

(defn resolve-payload-parameter
[request]
;; Using `or` instead of not-found to prevent unnecessary lookups/evaluation
(or (get-in request [:json-params :payload])
(get-in request [:transit-params :payload])
(get-in request [:edn-params :payload])
;; There's no technical reason not to support forms,
;; except for the lack of symmetry wrt `:payload`
(:form-params request)))

(def eav (juxt :e :a :v))

Expand Down Expand Up @@ -397,7 +411,7 @@
(let [;args# (merged-parameters ~'request)
args# (mapv
#(select-keys % ~(vec properties))
(get-in ~'request [:json-params :payload]))
(resolve-payload-parameter ~'request))
tx-data# (~(tx-processor db-op) args#)
conn# (:conn ~'request)
response-body# (apply-tx
Expand Down