reqwest HTTP Client Library

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

APIDescription
reqwest.methodSet the HTTP request method.
reqwest.headerSet one or a group of request headers.
reqwest.cookieSet the Cookie request header.
reqwest.cookie_storeEnable or disable cookie storage for the current requesting client.
reqwest.bodySet the string request body.
reqwest.jsonSet the JSON request body.
reqwest.formSet application/x-www-form-urlencoded form request body.
reqwest.multipartSet multipart/form-data request body.
reqwest.timeoutSet the request timeout.
reqwest.queryAppend URL query parameters.
reqwest.proxySet HTTP/HTTPS proxy.
reqwest.redirect_policySet redirect policy.
reqwest.sendSend an HTTP request synchronously and return a response object.

Examples

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 this send() 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 variableDefault valueDescription
BT_HTTP_CLIENT_POOLtrueWhether to enable the HTTP client pool.
BT_HTTP_CLIENT_POOL_LIMIT32, maximum 1024Maximum number of client configuration groups to retain.
BT_HTTP_CLIENT_IDLE_TTL_MS300000client idle retention time, in milliseconds; 0 means not to be eliminated based on idle time.
BT_HTTP_SLOW_MS0Slow HTTP call log threshold, in milliseconds; 0 means off.