@talesmgodois/trex
v0.2.3
Published
Terminal-based tool for HTTP requests (Trex)
Downloads
500
Readme
trex
Install
bun installRun
Trex starts a small CLI from src/index.ts.
Examples:
# list registered requests/functions (from config)
bun run ./src/index.ts list
# execute a request by name
bun run ./src/index.ts req getTodo
# run with a jq filter (jq syntax)
bun run ./src/index.ts req getTodo --filter .titleConfiguration (trex.config.ts)
Trex loads a config file on startup and executes it once.
- Default config location:
src/trex.config.ts - Custom config: pass
--config <path>bun run ./src/index.ts --config ./samples/trex.config.ts req getTodo
What you put in trex.config.ts
Your config should register:
- Environments
import { env, regEnv } from "../src/trex.lib.ts";
regEnv("public", { JSON_BASE_URL: "https://jsonplaceholder.typicode.com" });
env("public"); // selects the active env- HTTP requests (public APIs, etc.)
Use
addHttpFunc()(recommended for testing):
import { addHttpFunc } from "../src/trex.lib.ts";
addHttpFunc("getTodo", {
method: "GET",
url: "{{JSON_BASE_URL}}/todos/1",
});- Pure TS/JS functions (optional)
import { addFunction } from "../src/trex.lib.ts";
export const sum = addFunction("sum", ({ a, b }: { a: number; b: number }) => a + b);Templates
The engine supports:
{{VAR_NAME}}-> replaced from the active environment vars[[requestName.path]]-> replaced from the data saved by a previous request (afterreq <requestName>)
Samples
This repo includes samples/trex.config.ts, which hits JSONPlaceholder (public test API).
Run it:
bun run ./src/index.ts --config ./samples/trex.config.ts list
bun run ./src/index.ts --config ./samples/trex.config.ts req getTodo
bun run ./src/index.ts --config ./samples/trex.config.ts req getTodosForUser1
bun run ./src/index.ts --config ./samples/trex.config.ts req createPostSampleTip: try --filter too:
bun run ./src/index.ts --config ./samples/trex.config.ts req getTodo --filter .title