hutc-0.1.0 is not a library.
hutc
Lua-driven HTTP API test runner built in Rust.
Installation
Install from crates.io:
Quick Start
- Generate Lua language-server definitions:
This creates tests/hutc.defs.lua.
- Create a test file at
tests/health.lua:
local client = http
client:
test
- Run tests:
Default Paths
hutc testreads.luafiles fromtestshutc initwritestests/hutc.defs.lua
Lua API
Globals
| Function | Purpose |
|---|---|
test(name, fn) |
Registers a test case |
expect(value) |
Creates an assertion object |
http() |
Creates an HTTP client |
log(...) |
Prints debug values |
Assertions
expect(value) returns an Expect object:
| Method | Description |
|---|---|
:msg("message") |
Adds custom message prefix on assertion failure |
:to_equal(expected) |
Asserts equality |
:to_not_equal(expected) |
Asserts inequality |
:to_exist() |
Asserts value is not nil |
Example:
expect::
expect:
HTTP Client
Create a client:
local client = http
client:
Create a request with client:req(), then chain request-builder methods:
| Method | Description |
|---|---|
:path("/users") |
Relative path (uses base_url) |
:url("https://...") |
Absolute URL (overrides path/base_url) |
:header("k", "v") |
Single header |
:headers({ k = "v" }) |
Multiple headers |
:query("k", "v") |
Single query param |
:queries({ k = "v" }) |
Multiple query params |
:body("text") |
Plain text body |
:body_bytes("raw") |
Raw bytes body |
:json('{"k":"v"}') |
JSON body as raw JSON string |
:form({ k = "v" }) |
Form body |
:timeout_ms(5000) |
Request timeout in milliseconds |
:bearer("token") |
Sets Authorization: Bearer <token> |
Execute with one of:
get, post, put, patch, delete, send
send uses current/default method (GET unless set by another verb).
HTTP Response Shape
Each request returns a response table:
| Field | Type | Description |
|---|---|---|
status |
integer |
HTTP status code |
ok |
boolean |
true for 2xx responses |
body |
string |
Raw response body |
url |
string |
Final response URL |
duration_ms |
integer |
Request duration |
headers |
table<string, string> |
Response headers |
json |
any? |
Parsed JSON (if body is valid JSON) |
End-to-End Example
local client = http
client:
test
test
Development
Run from source: