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
|
(config:add :client
|
||||||
:class 'client:config
|
:class 'client:config
|
||||||
:base-url "http://localhost:8899"
|
: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)
|
(:alx :alexandria)
|
||||||
(:jzon :com.inuoe.jzon))
|
(:jzon :com.inuoe.jzon))
|
||||||
(:export #:config #:base-url #:api-path #:doc-path
|
(:export #:config #:base-url #:api-path #:doc-path
|
||||||
#:get-page #:send-message))
|
#:get-page #:send-message
|
||||||
|
#:urlencoded #:json))
|
||||||
|
|
||||||
(in-package :scopes/web/client)
|
(in-package :scopes/web/client)
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
(:message :scopes/core/message)
|
(:message :scopes/core/message)
|
||||||
(:response :scopes/web/response)
|
(:response :scopes/web/response)
|
||||||
(:util :scopes/util)
|
(:util :scopes/util)
|
||||||
(:alx :alexandria))
|
(:alx :alexandria)
|
||||||
|
(:jzon :com.inuoe.jzon))
|
||||||
(:export #:config #:address #:port #:routes
|
(:export #:config #:address #:port #:routes
|
||||||
#:*listener* #:setup #:start #:stop
|
#:*listener* #:setup #:start #:stop
|
||||||
#:content
|
#:content
|
||||||
|
@ -91,7 +92,7 @@
|
||||||
(defun message-handler (ctx env &key html-responder)
|
(defun message-handler (ctx env &key html-responder)
|
||||||
(let* ((resp (response:setup ctx env :html-responder html-responder))
|
(let* ((resp (response:setup ctx env :html-responder html-responder))
|
||||||
(msg (message:create (head env)
|
(msg (message:create (head env)
|
||||||
:data (plist (post-data env))
|
:data (post-data env)
|
||||||
:customer (core:mailbox resp))))
|
:customer (core:mailbox resp))))
|
||||||
;(util:lgd msg)
|
;(util:lgd msg)
|
||||||
;(request:process msg ctx env :response resp)
|
;(request:process msg ctx env :response resp)
|
||||||
|
@ -112,8 +113,11 @@
|
||||||
(defun post-data (env)
|
(defun post-data (env)
|
||||||
(if (getf env :content-length)
|
(if (getf env :content-length)
|
||||||
(let* ((raw (getf env :raw-body))
|
(let* ((raw (getf env :raw-body))
|
||||||
(str (read-line (flexi-streams:make-flexi-stream raw))))
|
(str (read-line (flexi-streams:make-flexi-stream raw)))
|
||||||
(quri.decode:url-decode-params str))))
|
(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)
|
(defun plist (alst)
|
||||||
(let ((a2 (mapcar #'(lambda (p) (cons (util:to-keyword (car p)) (cdr p))) alst)))
|
(let ((a2 (mapcar #'(lambda (p) (cons (util:to-keyword (car p)) (cdr p))) alst)))
|
||||||
|
|
Loading…
Add table
Reference in a new issue