web/client: test with json; web/server: handle json correctly
This commit is contained in:
parent
8e9995cf9a
commit
25d4301c75
3 changed files with 13 additions and 6 deletions
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)))
|
||||
|
|
Loading…
Add table
Reference in a new issue