"Curl/Wget for uLisp"
Or: An HTTP(s) get/post/put function for uLisp
Last edited on July 26, 2024
Oh, I forgot to continue posting… I just published a quite comprehensive HTTP function supporting put, post, get, auth, HTTP and HTTPS, and more for uLisp at ulisp-esp-m5stack.
Activate #define enable_http and #define enable_http_keywords to get it; the keywords used by the http function are to be enabled separately as they might be used more general and not just by this function.
Note that you need to connect to the internet first. Usually with WIFI-CONNECT.
Here is the full documentation with example calls:
Function http Syntax: http url &key verbose (https t) auth (user default_username) (password default_password) accept content-type (method :get) data => result-string
Arguments and values:
verbose---t, or nil (the default); affects also debug output of the argument
decoding itself and should be put in first position in a call for full effect.
https---t (the default), nil, or a certificate as string; uses default certificate in C string root_ca if true; url needs to fit: "http://..." for true and and "https://..." for false.
auth---t, or nil (the default).
user---a string, or nil (the default); uses default value in C string default_username if nil; only used if :auth t.
password---a string, or nil (the default); uses default value in C string default_password if nil; only used if :auth t.
accept---nil (the default), or a string.
content-type---nil (the default), or a string.
method---:get (the default), :put, or :post.
data---nil (the default), or a string; only necessary in case of :method :put or :method :post; error for :method :get.
Examples: ;; HTTP GET: (http "http://192.168.179.41:2342" :https nil) ;; HTTP PUT: (http "http://192.168.179.41:2342" :https nil :accept "application/n-quads" :content-type "application/n-quads" :auth t :user "foo" :password "bar" :method :put :data (format nil "<http://example.com/button> <http://example.com/pressed> \"~a\" .~%" (get-time)))
It can be tested with an minimal HTTP server simulation using bash and netcat:
while true; do echo -e "HTTP/1.1 200 OK\n\n $(date)" | nc -l -p 2342 -q 1; done
See also Again more features for uLisp on M5Stack (ESP32):
time via NTP, lispstring without escaping and more space, More features for uLisp on M5Stack (ESP32):
flash support, muting of the speaker and backlight control and uLisp on M5Stack (ESP32).