Skip to content

Lightweight Express middleware for automatic TOON request parsing and response serialization. Works with JSON middleware and supports both TypeScript and JavaScript.

License

Notifications You must be signed in to change notification settings

burakyzn/express-toon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm version npm downloads bundle size ESM only license

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-toon

Usage

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/toon Content-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

About

Lightweight Express middleware for automatic TOON request parsing and response serialization. Works with JSON middleware and supports both TypeScript and JavaScript.

Topics

Resources

License

Stars

Watchers

Forks