Reference · HTTP client

http.patch

signature
http.patch(str, any=, map | null=, map | null=) -> map | error(str)

What it does

Sends a PATCH with a body, as http.post sends a POST, and gives the answer as a map { status, ok, headers, body, json }. A map or a list goes as JSON, text as text/plain, HTML as text/html; null sends no body. Headers come third, options (redirects, public_only, timeout, ca, cert, key) fourth. A 307 or 308 is followed with the same method and body; to another origin, only the accept, accept-language, content-type and user-agent headers go on, as for http.get.

Examples

in a program
let r = http.patch(`https://api.example.com/users/${id}`, { role: "admin" })print(r.status)http.patch(url, patch, { "content-type": "application/json-patch+json" })
print(http.patch("http://127.0.0.1:9/users/1", { role: "admin" }))print(http.patch("not a url", { role: "admin" }))
output
err("http: http://127.0.0.1:9/users/1: Connection Failed: Connect error: Connection refused (os error 111)")err("http: not an http(s) URL: not a url")

Edge cases

print(http.patch("http://127.0.0.1:9/users/1", null, { authorization: "x" }))print(http.patch("http://127.0.0.1:9/users/1", [{ op: "replace", path: "/role", value: "admin" }], {}, { timeout: 2 }))
output
err("http: http://127.0.0.1:9/users/1: Connection Failed: Connect error: Connection refused (os error 111)")err("http: http://127.0.0.1:9/users/1: Connection Failed: Connect error: Connection refused (os error 111)")

Errors

Not reaching the server is an error value; a bad argument or option is a runtime error.

let r = http.patch("http://127.0.0.1:9/users/1", { role: "admin" })print(is_err(r), r.error)
output
true http: http://127.0.0.1:9/users/1: Connection Failed: Connect error: Connection refused (os error 111)
this one fails
print(http.patch("http://127.0.0.1:9/users/1", {}, {}, { timeout: 0 }))
output
line 1: `http.patch`: `timeout` is seconds, more than 0 and up to 300, got 0

Chaining

The URL is the first argument; ? passes an error value on.

in a program
route POST /users/:id/promote {    http.patch(`${upstream}/users/${id}`, { role: "admin" })?    redirect(`/users/${id}`)}
print("not a url" | http.patch({ a: 1 }) | is_err)
output
true

See also

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

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

Thread 0 posts

On http.patch(): 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