express-toon
v1.2.0
Published
A lightweight Express middleware that adds automatic TOON request parsing and TOON response serialization.
Maintainers
Readme
express-toon
express-toon is a lightweight Express middleware and request/response serializer for automatic TOON format support. Effortlessly parse TOON requests and send TOON responses in your API. Works seamlessly alongside JSON middleware and is fully compatible with both TypeScript and JavaScript in your existing Express apps.
Installation
npm install express-toonUsage
const app = express();
app.use(toonize());
app.post('/api/users', (req, res) => {
// req.body contains parsed TOON data
res.toon({ success: true, user: req.body });
});toonize() accepts an optional options object:
| Option | Type | Default | Description |
| --- | --- | --- | --- |
| limit | string \| number | "100kb" | Maximum request body size for text/toon payloads |
| inflate | boolean | true | Whether to inflate compressed bodies |
| verify | (req, res, buf, encoding) => void | — | Verify function called by the body parser |
| defaultCharset | string | "utf-8" | Default charset when none is specified |
Features
- 🚀 Automatic TOON request parsing for
text/toonContent-Type - 📦 Simple TOON response serialization with
res.toon() - 🔄 Works with JSON: Use alongside
express.json()without conflicts - ⚡ Zero configuration: Plug-and-play middleware
- 🛡️ TypeScript types included for type safety
- 🧩 Composable: Use as a standalone or with other Express middlewares
How It Works
The middleware:
- Only processes requests with
Content-Type: text/toon - Parses TOON data into
req.body(deserializer) - Adds
res.toon(data)method for sending TOON responses (serializer) - Works as a request/response parser for APIs using TOON
License
MIT License © 2025-PRESENT Burak Yazan
