npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zenweb/body

v4.0.8

Published

Zenweb Body module

Downloads

251

Readme

body - 请求内容解析

请求内容解析

功能说明

解析客户端发送的 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;
}

依赖模块

  • @zenweb/inject
  • @zenweb/helper

配置项

| 配置项 | 类型 | 默认值 | 功能 | | ----- | --- | ----- | ---- | | 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] | 内容解析器

Core 挂载项

Context 挂载项

可注入对象

  • singleton

    • BodyOption
  • request

    • RawBody
    • TextBody
    • Body
    • ObjectBody
    • BodyHelper

全局模式

| 方法 | 功能 | | ----- | ---- | | getRawBody() | 取得当前请求原始请求内容 | getTextBody() | 取得当前请求文本内容,经过文字编码转换 | getObjectBody() | 取得当前请求数据对象 | $body | BodyHelper 对象快捷方式

其他扩展格式解析

xml