https://github.com/oowl/lua-reqwest
A simple Lua HTTP client based on Rust reqwest library.
https://github.com/oowl/lua-reqwest
lua luajit mlua openresty openresty-module reqwest rust
Last synced: 5 months ago
JSON representation
A simple Lua HTTP client based on Rust reqwest library.
- Host: GitHub
- URL: https://github.com/oowl/lua-reqwest
- Owner: oowl
- License: apache-2.0
- Created: 2024-09-05T09:10:18.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-05-28T11:06:05.000Z (8 months ago)
- Last Synced: 2025-05-28T11:19:52.505Z (8 months ago)
- Topics: lua, luajit, mlua, openresty, openresty-module, reqwest, rust
- Language: Rust
- Homepage:
- Size: 24.4 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lua-reqwest
A simple Lua HTTP client based on [reqwest](https://docs.rs/reqwest/latest/reqwest/).
## Installation
```sh
# install from local source
luarocks make reqwest-0.1.0-1.rockspec
# install from luarocks
luarocks install lua-reqwest
```
## APIS
### reqwest.request(url, options)
- `url` (string): The URL to request.
- `options` (table): The request options.
- `method` (string): The request method, default is `GET`.
- `headers` (table): The request headers.
- `body` (string): The request body.
- `version` (number): The HTTP version, default is `1.1`.
- `timeout` (number): The request timeout in seconds, default is `30`.
- `connect_timeout` (number): The request connect timeout in seconds.
- `tls_verify` (boolean): Verify the TLS certificate, default is `true`.
## Example
```lua
local reqwest = require("reqwest")
local cjson = require("cjson")
local res, err = reqwest.request("https://cloudflare.com/cdn-cgi/trace", { headers = { ["User-Agent"] = "reqwest" }, version = 2 })
print("err: " .. tostring(err))
print("res: " .. cjson.encode(res))
```
```sh
╰─$ luajit test.lua
err: nil
res: {"status":200,"body":"fl=464f193\nh=cloudflare.com\nip=1.1.1.1\nts=1725552998.6\nvisit_scheme=https\nuag=reqwest\ncolo=SJC\nsliver=none\nhttp=http\/2\nloc=US\ntls=TLSv1.3\nsni=plaintext\nwarp=off\ngateway=off\nrbi=off\nkex=X25519\n","headers":{"date":"Thu, 05 Sep 2024 16:16:38 GMT","cf-ray":"8be786613aeacf2e-SJC","content-type":"text\/plain","x-content-type-options":"nosniff","server":"cloudflare","cache-control":"no-cache","x-frame-options":"DENY","access-control-allow-origin":"*","expires":"Thu, 01 Jan 1970 00:00:01 GMT"}}
```