Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
request-is-better
Advanced tools
request-is-better is a TypeScript library which makes it easier to use request-response calls on any channel that implements a send-receive message interface.
Request-is-better is a TypeScript library which makes it easier to use request-response calls on any channel that implements a send-receive message interface. Like the lib? Support it with a star!
send
immediatly than this library will also return the result immediatly.npm i request-is-better
pnpm i request-is-better
yarn i request-is-better
Assuming your channel implements the send(MESSAGE)
and on("message", CALLBACK)
interface:
This is useful if your messaging channel does not use the standard send and on function signatures:
import { expect } from "chai";
import WebSocket, { Server } from "ws";
// In your code use the following line instead of "./index.js";
// import { messagingToRequestResponse } from "request-is-better";
import { messagingToRequestResponse } from "./index.js";
describe("ws_for_readme.test.ts", () => {
it("client requests server", async () => {
let server = new Server({ port: 8080 });
let client: WebSocket | undefined;
try {
// Stub ws echo server
server.on("connection", async (ws) => {
ws.on("message", (message) => ws.send(message));
});
// Ws client connected to the server
client = new WebSocket("ws://localhost:8080");
// Next two lines is how to use 'messagingToRequestResponse' from request is better
const { request, onReceive } = messagingToRequestResponse({ send: (m: unknown) => client!.send(JSON.stringify(m)) });
client.on("message", (m: unknown) => onReceive(JSON.parse(m as string)));
// We have to wait for client to connect to the server
await new Promise((resolve) => {
client!.on("open", async () => {
resolve(1);
});
});
// And now we can use 'request'
const response = await request({ msg: "message1" });
expect(response).to.eql({ msg: "message1" });
} finally {
client?.close();
server.close();
}
});
});
See *.test.ts
files in git repository src
folder
send: (m: unknown) => Promise<void> | void
A function that sends a message through your messaging system.
ignoreUnknownResponses?: boolean
If set to true, the library will ignore responses that do not match a known request ID. Defaults to false.
timeout?: number
If provided, each request will automatically be rejected after this duration (in milliseconds) if no response is received.
Please submit an issue or pull request on our GitHub repository. https://github.com/yuyaryshev/request-is-better
Like the lib? Support it with a star!
The Unlicense
FAQs
request-is-better is a TypeScript library which makes it easier to use request-response calls on any channel that implements a send-receive message interface.
The npm package request-is-better receives a total of 1 weekly downloads. As such, request-is-better popularity was classified as not popular.
We found that request-is-better demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.