Skip to content

Latest commit

 

History

History
30 lines (23 loc) · 1.17 KB

rontolisp-query-params.md

File metadata and controls

30 lines (23 loc) · 1.17 KB

rontolisp:query-params

(rontolisp:query-params query)

Parses a query string such as "a=1&b=two&flag" into an alist of (key . value) string pairs. Keys and values are url-decoded with rontolisp:url-decode; a key without = gets the value ""; duplicate keys are preserved in order; empty segments are skipped. nil (a request without a query string) yields nil, so (rontolisp:query-params (getf env :query-string)) is always safe inside an rontolisp:http-handler handler.

(rontolisp:query-params "a=1&b=two&flag")   ; => (("a" . "1") ("b" . "two") ("flag" . ""))
(rontolisp:query-params "q=%E3%81%82&q=2")   ; => (("q" . "あ") ("q" . "2"))
(rontolisp:query-params nil)   ; => NIL

The alist prints readably and works with assoc:

(cdr (assoc "b" (rontolisp:query-params "a=1&b=two") :test #'string=))   ; => "two"

Backend support

Works on every backend and in every WASM mode (Preview 1 included): the library is written in rontolisp itself and is compiled into the program when used. For the common "value of one name" lookup use rontolisp:query-param.