Reference · HTTP client

http.delete

signature
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

in a program
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"))
output
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

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 }))
output
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)
output
true http: http://127.0.0.1:9/items/1: Connection Failed: Connect error: Connection refused (os error 111)
this one fails
print(http.delete("http://127.0.0.1:9/items/1", {}, { cache: 10 }))
output
line 1: `http.delete`: `cache` keeps the answers of GET requests, not DELETE

Chaining

The URL is the first argument, so url | http.delete works, and ? passes an error value on to the caller.

in a program
route DELETE /items/:id {    http.delete(`${upstream}/items/${id}`)?    redirect("/items")}
print("http://127.0.0.1:9/x" | http.delete | is_err)
output
true

See also

http.get, http.post, http.request, is_err

Thread
7Useful? Like it, or add to its thread below.

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