Complete signatures, types, and examples are available in the source repository README and TypeScript declarations.
05
Body lifetime, limits, and backpressure
swm-core deliberately keeps cost and data lifetime visible. These rules matter for correct production code.
Read lazy bodies before the first await
In the default mode, call ctx.body(), buffer(), text(), or json() before the first asynchronous operation. Otherwise uWS body events may arrive before a reader is registered.
Use prefetch for asynchronous auth
Enable prefetch globally or per route when authorization or database work must finish before reading the body. Bytes are collected early while JSON parsing remains lazy.
Bound aggregate memory
maxBodySize limits one request; maxBodyBudget limits all bodies being collected. Budget exhaustion returns 503, while a per-request limit returns 413.
Check the send status
WSContext.send() returns 1 on success, 0 on backpressure, and 2 when a message is dropped because of a limit.
Do not retain HttpContext
HttpContext is reused between requests. WSContext lives for the connection, but must not be used after onClose.
06
When to use the low-level binding
swm-core fits most services. Move to swm-uws when you need direct compatibility with the regular uWebSockets.js App() API and are prepared to manage request and response object lifetimes yourself.
JavaScripttransport-choice.js
// High-level serverimport Server from'@swarmmachina/swm-core'// Low-level bindingimport uWS from'@swarmmachina/swm-uws'