reqwest HTTP Client Library
reqwest HTTP Client Library
Function
reqwest(url) Creates a synchronous HTTP request builder, supporting method, header, cookie, cookie_store, body, json, form, multipart, timeout, query, proxy, redirect_policy and send.
API List
| API | Description |
|---|---|
| reqwest.method | Set the HTTP request method. |
| reqwest.header | Set one or a group of request headers. |
| reqwest.cookie | Set the Cookie request header. |
| reqwest.cookie_store | Enable or disable cookie storage for the current requesting client. |
| reqwest.body | Set the string request body. |
| reqwest.json | Set the JSON request body. |
| reqwest.form | Set application/x-www-form-urlencoded form request body. |
| reqwest.multipart | Set multipart/form-data request body. |
| reqwest.timeout | Set the request timeout. |
| reqwest.query | Append URL query parameters. |
| reqwest.proxy | Set HTTP/HTTPS proxy. |
| reqwest.redirect_policy | Set redirect policy. |
| reqwest.send | Send an HTTP request synchronously and return a response object. |
Examples
response = reqwest('https://example.com').send() result = type(response) // Output: Object print result
Notes
- The current VM is a synchronous model, send() will wait for the HTTP request to be completed synchronously; the underlying process-level I/O runtime is reused.
- The HTTP client pool is enabled by default and is grouped and reused by proxy and redirection policies; the pool status can be viewed through
BT.stats().http. -
cookie_store(true)only acts on thissend()and its redirect link, and does not enter the shared client pool to avoid cross-request cookie pollution. - Body, json, form, and multipart will all set the request body; the last request body set in the same request takes effect.
HTTP client pool default configuration:
| Environment variable | Default value | Description |
|---|---|---|
| BT_HTTP_CLIENT_POOL | true | Whether to enable the HTTP client pool. |
| BT_HTTP_CLIENT_POOL_LIMIT | 32, maximum 1024 | Maximum number of client configuration groups to retain. |
| BT_HTTP_CLIENT_IDLE_TTL_MS | 300000 | client idle retention time, in milliseconds; 0 means not to be eliminated based on idle time. |
| BT_HTTP_SLOW_MS | 0 | Slow HTTP call log threshold, in milliseconds; 0 means off. |