Reference · HTTP client
http.delete
http.delete(str, map | null=, map | null=) -> map | error(str)What it does
Sends a DELETE to a URL, with no body, and gives the answer as a map { status, ok, headers, body, json }, as http.get does. The second
argument is a map of request headers, the third a map of options: redirects,
public_only, timeout, ca, cert and key. A 307 or 308 is followed with
the same method; to another origin, only the accept, accept-language,
content-type and user-agent headers go on, as for
http.get. Every HTTP status is an answer; failing to reach the
server is an error value.
Examples
let r = http.delete(`https://api.example.com/items/${id}`, { authorization: `Bearer ${key}` })if !r.ok { reply 502 `could not delete: ${r.status}` }print(http.delete("http://127.0.0.1:9/items/1"))print(http.delete("not a url"))err("http: http://127.0.0.1:9/items/1: Connection Failed: Connect error: Connection refused (os error 111)")err("http: not an http(s) URL: not a url")Edge cases
- There is no body argument: a DELETE with a body is
http.request("DELETE", url, body). - A 404 for something already gone is an answer with
okfalse andstatus404, not an error value. cacheis for GET: giving it here is a runtime error.public_only: truerefuses addresses that are not on the public internet before connecting.
print(http.delete("http://127.0.0.1:9/items/1", null, { timeout: 2, redirects: 0 }))print(http.delete("http://127.0.0.1:9/items/1", {}, { public_only: true }))err("http: http://127.0.0.1:9/items/1: Connection Failed: Connect error: Connection refused (os error 111)")err("http: http://127.0.0.1:9/items/1: refused by public_only: 127.0.0.1 is not on the public internet")Errors
Not reaching the server is an error value; a bad argument (a URL that is not a string,
headers that are not a map, an unknown option, cache) is a runtime error.
let r = http.delete("http://127.0.0.1:9/items/1")print(is_err(r), r.error)true http: http://127.0.0.1:9/items/1: Connection Failed: Connect error: Connection refused (os error 111)print(http.delete("http://127.0.0.1:9/items/1", {}, { cache: 10 }))line 1: `http.delete`: `cache` keeps the answers of GET requests, not DELETEChaining
The URL is the first argument, so url | http.delete works, and ? passes an error
value on to the caller.
route DELETE /items/:id { http.delete(`${upstream}/items/${id}`)? redirect("/items")}print("http://127.0.0.1:9/x" | http.delete | is_err)trueSee also
http.get, http.post, http.request, is_err
Thread 0 posts
On http.delete(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo