@argos-js/net
v0.1.2
Published
Networking and HTTP adapter layer connecting Argox native core to Argos-JS runtime
Readme
@argos-js/net
High-performance networking and HTTP abstraction layer connecting the Argox native engine to the Argos-JS runtime.
Overview
@argos-js/net provides the low-level HTTP bridge between native Rust FFI bindings (@argos-js/argox-core) and TypeScript routing/middleware systems. It manages request contexts (ArgosContext), header normalization, cookie management, form/multipart parsing, and in-memory request injection.
Features
- ⚡ Native FFI Bridge: High-throughput memory exchange with the Argox engine.
- 📦 Isolated Request Context (
ArgosContext): Memory-safe execution context per incoming request. - 🧪 Zero-Socket In-Memory Injection (
inject()): Execute and test request pipelines directly in memory without binding network ports. - 🍪 RFC 6265 Cookies & Multipart Form Engine: Built-in cookie management and binary multipart/form-data parser.
- 🛡️ Semantic HTTP Status & Error Handling: Comprehensive status codes and structured HTTP errors.
In-Memory Request Injection (adapter.inject)
The networking layer exposes inject() for simulating HTTP requests without opening operating system sockets or network interfaces.
InjectOptions
export interface InjectOptions {
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | string;
url: string;
headers?: Record<string, string>;
payload?: unknown;
body?: unknown;
query?: Record<string, string | number | boolean>;
}InjectResponse
export interface InjectResponse {
statusCode: number;
headers: Record<string, string | string[]>;
body: string;
json<T = any>(): T;
}Fast Testing Example
import { ArgoxNativeAdapter } from '@argos-js/net';
const adapter = new ArgoxNativeAdapter();
adapter.useHandler(async (ctx) => {
const [pathname] = ctx.path.split('?');
if (pathname === '/api/ping') {
return ctx.json({ pong: true, time: Date.now() });
}
return ctx.json({ error: 'Not Found' }, 404);
});
// Run simulated in-memory request without binding any TCP port
const response = await adapter.inject({
method: 'GET',
url: '/api/ping',
});
console.log(response.statusCode); // 200
console.log(response.json()); // { pong: true, time: ... }License
MIT
