diff --git a/test/etc/config-web.lisp b/test/etc/config-web.lisp index 0d57f9a..aff7080 100644 --- a/test/etc/config-web.lisp +++ b/test/etc/config-web.lisp @@ -25,4 +25,6 @@ (config:add :client :class 'client:config :base-url "http://localhost:8899" - :doc-path "/" :api-path "/hx/") + :doc-path "/" :api-path "/hx/" + :data-renderer #'client:json +) diff --git a/web/client.lisp b/web/client.lisp index 3bf9e3e..2521d8b 100644 --- a/web/client.lisp +++ b/web/client.lisp @@ -10,7 +10,8 @@ (:alx :alexandria) (:jzon :com.inuoe.jzon)) (:export #:config #:base-url #:api-path #:doc-path - #:get-page #:send-message)) + #:get-page #:send-message + #:urlencoded #:json)) (in-package :scopes/web/client) diff --git a/web/server.lisp b/web/server.lisp index f433812..2005a83 100644 --- a/web/server.lisp +++ b/web/server.lisp @@ -7,7 +7,8 @@ (:message :scopes/core/message) (:response :scopes/web/response) (:util :scopes/util) - (:alx :alexandria)) + (:alx :alexandria) + (:jzon :com.inuoe.jzon)) (:export #:config #:address #:port #:routes #:*listener* #:setup #:start #:stop #:content @@ -91,7 +92,7 @@ (defun message-handler (ctx env &key html-responder) (let* ((resp (response:setup ctx env :html-responder html-responder)) (msg (message:create (head env) - :data (plist (post-data env)) + :data (post-data env) :customer (core:mailbox resp)))) ;(util:lgd msg) ;(request:process msg ctx env :response resp) @@ -112,8 +113,11 @@ (defun post-data (env) (if (getf env :content-length) (let* ((raw (getf env :raw-body)) - (str (read-line (flexi-streams:make-flexi-stream raw)))) - (quri.decode:url-decode-params str)))) + (str (read-line (flexi-streams:make-flexi-stream raw))) + (ct (getf env :content-type))) + (if (str:containsp "json" ct) + (alx:hash-table-plist (jzon:parse str :key-fn #'util:to-keyword)) + (plist (quri.decode:url-decode-params str)))))) (defun plist (alst) (let ((a2 (mapcar #'(lambda (p) (cons (util:to-keyword (car p)) (cdr p))) alst)))