web/client: convert data to alist for dexador (url-encoded post-data)

This commit is contained in:
Helmut Merz 2024-06-24 09:28:04 +02:00
parent 05747fa5cc
commit 288563d373
3 changed files with 16 additions and 5 deletions

View file

@ -39,5 +39,5 @@
(has-prefix (client:get-page client msg) "Hello Fileserver!")))
(deftest test-message (client)
(let ((msg (message:simple-message '(:test :data))))
(let ((msg (message:simple-message '(:test :data) '(:info "test data"))))
(== (client:send-message client msg) "Hello World!")))

View file

@ -4,7 +4,8 @@
(:use :common-lisp)
(:local-nicknames (:config :scopes/config)
(:core :scopes/core)
(:message :scopes/core/message))
(:message :scopes/core/message)
(:alx :alexandria))
(:export #:config #:base-url #:api-path #:doc-path
#:get-page #:send-message))
@ -27,8 +28,14 @@
(defun send-message (ctx msg)
(let* ((cfg (core:config ctx))
(url (str:concat (base-url cfg) (api-path cfg) (msgpath msg))))
(dex:get url)))
(dex:post url :content (data-as-alist (message:data msg)))))
(defun msgpath (msg)
(let ((lst (loop for p in (message:head-as-list msg) when p collect p)))
(str:join "/" (mapcar #'string-downcase lst))))
(defun data-as-alist (data)
(if (symbolp (car data)) ; seems to be a property list
(mapcar #'(lambda (p) (cons (string-downcase (car p)) (cdr p)))
(alx:plist-alist data))
data))

View file

@ -42,8 +42,12 @@
(lack/component:call file-app env)))
(defun message-handler (ctx env)
(print env)
'(200 (:content-type "text/plain") ("Hello World!")))
;(print env)
;(print (read-line (getf env :raw-body)))
(let ((head (getf env :message-head))
(data (read-line (getf env :raw-body))))
(format t "~&message head ~s, data ~s~%" head data)
'(200 (:content-type "text/plain") ("Hello World!"))))
(defun select-app (ctx env)
(let ((path (cdr (str:split "/" (getf env :path-info)))))