Reference · reference
http module
use http is an HTTP client. It is built on rustls, so it has no dependency on the system TLS library. Every function returns Result[…, string] and takes an options Value as its last argument. The options argument is required: pass Value::Null for the defaults, or a Value::Map with any of the keys below. A response with an error status is still Ok; inspect status.
| Option | Type | Meaning |
|---|---|---|
| headers | map of string | request headers |
| timeout | int or float | seconds before the request is abandoned |
| redirects | bool | follow redirects, default true |
HttpResponse
rust
status: int,
body: string,
headers: Map,
}
The result of get and post.
get
rust
get
Sends a GET request and returns the response.
post
rust
post
Sends body in a POST request and returns the response. Set the content type with a headers entry.
download
rust
download
Fetches url and writes the body to the file at dest. It returns the number of bytes written. Pair it with the archive module to unpack what was fetched.
rust
use http
use value
let n = download?