From 93aa860bc6f889b5d7a00538c37bf08d2a99a095 Mon Sep 17 00:00:00 2001 From: harehare Date: Wed, 15 Jul 2026 22:24:27 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(mq-lang):=20add=20http=5F*=5Fj?= =?UTF-8?q?son=20builtins=20to=20parse=20HTTP=20responses=20as=20JSON?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add http_get_json/http_post_json/http_put_json/http_patch_json/http_delete_json to builtin.mq, composing the existing http() and _json_parse() builtins so callers can fetch a URL and get back a dict/array directly instead of a raw string. --- crates/mq-lang/builtin.mq | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/mq-lang/builtin.mq b/crates/mq-lang/builtin.mq index 30cbc43d1..61d8f0558 100644 --- a/crates/mq-lang/builtin.mq +++ b/crates/mq-lang/builtin.mq @@ -593,6 +593,29 @@ def http_delete(url, headers = {}): http(:delete, url, headers); # string), and returns the response body as a string def http_head(url, headers = {}): http(:head, url, headers); +# Performs an HTTPS GET request, optionally with the given headers (a dict of string to +# string), and parses the response body as JSON, returning the resulting data structure +def http_get_json(url, headers = {}): _json_parse(http(:get, url, headers)); + +# Performs an HTTPS POST request with the given body, optionally with the given headers +# (a dict of string to string), and parses the response body as JSON, returning the +# resulting data structure +def http_post_json(url, body, headers = {}): _json_parse(http(:post, url, body, headers)); + +# Performs an HTTPS PUT request with the given body, optionally with the given headers +# (a dict of string to string), and parses the response body as JSON, returning the +# resulting data structure +def http_put_json(url, body, headers = {}): _json_parse(http(:put, url, body, headers)); + +# Performs an HTTPS PATCH request with the given body, optionally with the given headers +# (a dict of string to string), and parses the response body as JSON, returning the +# resulting data structure +def http_patch_json(url, body, headers = {}): _json_parse(http(:patch, url, body, headers)); + +# Performs an HTTPS DELETE request, optionally with the given headers (a dict of string to +# string), and parses the response body as JSON, returning the resulting data structure +def http_delete_json(url, headers = {}): _json_parse(http(:delete, url, headers)); + # Prints the debug information of the given value(s). def debug(*args): if (len(args) == 1):