DOCUMENTATION
MIDDLEWARES
Parse Data
Introduction

Introduction

The parseData middleware in provides unified, secure, and flexible request parsing. It supports all major content types and allows fine-grained configuration at both global and route levels.

Supported Data Sources

  • Query parameters
  • URL parameters
  • JSON body
  • URL-encoded form data
  • Multipart form data (including file uploads)
  • Raw or text payloads

Key Features

  • ๐Ÿ”„ Automatic type conversion for strings โ†’ numbers, booleans, and dates.
  • ๐Ÿงฉ In-memory file handling for multipart uploads.
  • ๐Ÿงฐ Configurable parsing per route or globally.
  • ๐Ÿ›ก SQL injection protection with escapeSQL.
  • ๐Ÿงพ Unified MIME-type filtering and decompression support.
  • ๐Ÿ“ฆ Optional rawBody capture for signature verification.
  • โš™๏ธ Stream-safe and async-compatible for high performance.

Quick Start

Global Usage

import v from "vkrun";
 
const app = v.App();
 
// Enable Parse Data globally
app.parseData();
 
app.post("/example", (req: v.Request, res: v.Response) => {
  res.status(200).json({ parsed: req.body });
});
 
app.server().listen(3000, () => {
  console.log("โœ… Server running with Parse Data enabled");
});

Route-Level Override

You can also apply parseData() only to specific routes:

import { parseData } from "vkrun";
 
router.post(
  "/upload",
  parseData({
    body: { type: "multipart/form-data", limit: 5 * 1024 * 1024 }, // 5MB
    security: { escapeSQL: true },
  }),
  (req, res) => {
    console.log(req.body, req.files);
    res.status(200).end();
  }
);
Copyright ยฉ 2024 - 2025 MIT by Mario Elvio