lyriahttp
v1.0.0
Published
lyriahttp is a npm package to make your http requests more good.
Maintainers
Readme
LyriaHTTP
Advanced HTTP requests, WebSocket, caching, logging, and utilities in TypeScript and Node.js.
Installation
npm install lyriahttpRequires Node.js 18+ for native fetch support.
Usage (TypeScript / ESM)
Basic GET Request
import { HttpRequest, NexoResponse } from "lyriahttp";
async function main() {
const req = new HttpRequest("https://jsonplaceholder.typicode.com/todos/1");
const res: NexoResponse = await req.Send();
console.log("Status:", res.Status);
console.log("JSON Body:", res.json());
}
main();POST Request with JSON Body
import { HttpRequest } from "lyriahttp";
const req = new HttpRequest(
"https://jsonplaceholder.typicode.com/posts",
"POST",
{ title: "Hello", body: "World", userId: 1 },
{},
{ "Content-Type": "application/json" }
);
req.Send().then(res => console.log(res.json()));Using HttpQueue
import { HttpQueue, HttpRequest } from "lyriahttp";
const queue = new HttpQueue(3);
queue.add(new HttpRequest("https://jsonplaceholder.typicode.com/todos/1"));
queue.add(new HttpRequest("https://jsonplaceholder.typicode.com/todos/2"));
console.log("Queue size:", queue.size());Caching with ZephyrCache
import { ZephyrCache } from "lyriahttp";
const cache = new ZephyrCache();
cache.set("key1", { data: 123 }, 5000); // TTL 5 seconds
console.log(cache.get("key1")); // { data: 123 }WebSocket with LyriaSocket
import { LyriaSocket } from "lyriahttp";
const ws = new LyriaSocket("wss://echo.websocket.org");
ws.connect(
(msg) => console.log("Received:", msg),
() => console.log("Closed"),
(err) => console.error("Error:", err)
);
ws.send("Hello WebSocket!");Logger and Utilities
import { AstraLogger, OrionUtils } from "lyriahttp";
// Logging
AstraLogger.log("This is a log message");
// Utilities
const random = OrionUtils.randomString(10);
console.log("Random string:", random);
await OrionUtils.delay(500);
console.log("Waited 500ms");Notes
- ESM / TypeScript focused: use
import { ... } from "lyriahttp";. HttpRequestsupports GET, POST, PUT, DELETE, PATCH.LyriaSocketautomatically handles reconnect and heartbeat.- Cache, queue, logger, and utility functions are built-in and simple to use.
License
Apache-2.0
