
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
@zenweb/body
Advanced tools
请求内容解析
解析客户端发送的 JSON、Form-urlencoded、Text、二进制 等内容格式。
所支持的解析格式可扩展可自定义。默认支持格式:JSON、Form-urlencoded、Text
import { Context, mapping, Body, $body } from 'zenweb';
export class Controller {
@mapping({ path: '/', method: 'POST' })
post(body: Body) {
console.log(body.type); // POST body 内容类型
console.log(body.data); // POST Body 内容解析完成后的数据
}
@mapping({ path: '/', method: 'POST' })
async post() {
console.log(await getAge()); // 类型转换&校验
}
}
async function getAge() {
return (await $body.get({ age: '!int' })).age;
}
配置项 | 类型 | 默认值 | 功能 |
---|---|---|---|
encoding | string | 'utf-8' | 客户端未指定情况下,文本内容字符集的默认编码 |
limit | number | 1024 * 1024 | 提交内容尺寸限制,默认:1MB |
inflate | boolean | true | 是否支持 http 压缩传输的内容 |
textTypes | string[] | ['text/*', 'json', '+json', 'xml', '+xml', 'urlencoded'] | 可以被解析成 Text 格式的 mimetype |
parses | BodyParserClass[] | [JSONParser, URLEncodedParser] | 内容解析器 |
无
无
singleton
request
方法 | 功能 |
---|---|
$getRawBody() | 取得当前请求原始请求内容 |
$getTextBody() | 取得当前请求文本内容,经过文字编码转换 |
$getObjectBody() | 取得当前请求数据对象 |
$body | BodyHelper 对象快捷方式 |
FAQs
Zenweb Body module
The npm package @zenweb/body receives a total of 19 weekly downloads. As such, @zenweb/body popularity was classified as not popular.
We found that @zenweb/body demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.