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
2.4.3
Version published
Weekly downloads
279
-33.41%
Maintainers
1
Weekly downloads
 
Created
Source

ZenWeb Body module

ZenWeb

支持 Form 表单解析,和文件上传处理。

演示

import { Context, mapping } from 'zenweb';

export class Controller {
  @mapping({ path: '/', method: 'POST' })
  post(ctx: Context) {
    console.log(ctx.bodyType); // POST body 内容类型
    console.log(ctx.body); // POST Body 内容解析完成后的对象
  }

  @mapping({ path: '/file', method: 'POST' })
  fileUpload(ctx: Context) {
    console.log(ctx.files); // 上传文件列表
  }
}

支持的内容格式

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

  • json: json
  • x-www-form-urlencoded: form
  • text/xml: xml
  • text/*: text
  • form-data: multipart

配置项

主配置 BodyOption

类型默认值说明
jsonJsonOption | booleantrue解析 json 格式
formFormOption | booleantrue解析表单请求
xmlXMLOption | booleanfalse解析 xml 格式
textTextOption | booleantrue解析纯文本
multipartMultipartOption | booleantrue支持上传文件
methodsstring['POST', 'PUT', 'PATCH']哪些请求需要被处理

BaseOption

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

JsonOption extends BaseOption

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

MultipartOption extends FormidableOptions

类型默认值说明
maxFieldsSizenumberBaseOption.limit表单字段大小限制,除去文件部分

FormOption extends BaseOption

无其他配置项

TextOption extends BaseOption

无其他配置项

Keywords

web

FAQs

Package last updated on 22 Jun 2022

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