Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@zenweb/body

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zenweb/body

Zenweb Body module

npmnpm
Version
3.3.1
Version published
Weekly downloads
444
7.77%
Maintainers
1
Weekly downloads
 
Created
Source

ZenWeb Body module

ZenWeb

支持 JSON、Form 表单解析

演示

import { Context, mapping, Body, BodyHelper } 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' })
  post(body: BodyHelper) {
    console.log(body.get({ age: '!int' })); // 类型转换&校验
  }
}

支持的内容格式

通过客户端提交的 Content-Type 头信息判断内容格式

  • json: json
  • x-www-form-urlencoded: form
  • text/*: text

配置项

主配置 BodyOption

类型默认值说明
jsonJsonOption | booleantrue解析 json 格式
formFormOption | booleantrue解析表单请求
textTextOption | booleantrue解析纯文本

BaseOption

类型默认值说明
encodingstring'utf-8'内容编码
limitstring'1mb'内容大小限制

JsonOption extends BaseOption

类型默认值说明
strictbooleantrue严格模式, 提交的内容必须为 {} 或 [] 开头

Keywords

web

FAQs

Package last updated on 16 Mar 2023

Did you know?

Socket

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.

Install

Related posts