diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-08-31 18:03:05 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-08-31 18:03:05 -0400 |
| commit | a0ac652cd1eebdc42425b34f1685f8cb20cb4eea (patch) | |
| tree | b41c99f8f0fa62eb03d1f5df44d2c501cd5f2976 /examples/http | |
| parent | a571ccffd795a595e990a3405dcf977aafc33c6c (diff) | |
Simplify quotes by limiting to `,',"
Diffstat (limited to 'examples/http')
| -rw-r--r-- | examples/http/http.tm | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/examples/http/http.tm b/examples/http/http.tm index 3fe41ae2..8d111904 100644 --- a/examples/http/http.tm +++ b/examples/http/http.tm @@ -10,73 +10,73 @@ enum _Method(GET, POST, PUT, PATCH, DELETE) func _send(method:_Method, url:Text, data:Text?, headers:[Text]=[] -> HTTPResponse) chunks : @[Text] save_chunk := func(chunk:CString, size:Int64, n:Int64) - chunks.insert(C_code:Text(Text$from_strn(@chunk, @size*@n))) + chunks.insert(C_code:Text`Text$from_strn(@chunk, @size*@n)`) return n*size - C_code { + C_code ` CURL *curl = curl_easy_init(); struct curl_slist *chunk = NULL; curl_easy_setopt(curl, CURLOPT_URL, @(CString(url))); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, @save_chunk.fn); curl_easy_setopt(curl, CURLOPT_WRITEDATA, @save_chunk.userdata); - } + ` defer - C_code { + C_code ` if (chunk) curl_slist_free_all(chunk); curl_easy_cleanup(curl); - } + ` when method is POST - C_code { + C_code ` curl_easy_setopt(curl, CURLOPT_POST, 1L); - } + ` if posting := data - C_code { + C_code ` curl_easy_setopt(curl, CURLOPT_POSTFIELDS, @(CString(posting))); - } + ` is PUT - C_code { + C_code ` curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); - } + ` if putting := data - C_code { + C_code ` curl_easy_setopt(curl, CURLOPT_POSTFIELDS, @(CString(putting))); - } + ` is PATCH - C_code { + C_code ` curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PATCH"); - } + ` if patching := data - C_code { + C_code ` curl_easy_setopt(curl, CURLOPT_POSTFIELDS, @(CString(patching))); - } + ` is DELETE - C_code { + C_code ` curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); - } + ` else pass for header in headers - C_code { + C_code ` chunk = curl_slist_append(chunk, @(CString(header))); - } + ` - C_code { + C_code ` if (chunk) curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk); - } + ` code := Int64(0) - C_code { + C_code ``` CURLcode res = curl_easy_perform(curl); if (res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &@code); - } + ``` return HTTPResponse(Int(code), "".join(chunks)) func get(url:Text, headers:[Text]=[] -> HTTPResponse) |
