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

koapi-body

v2.0.8

Published

Full-featured [koa][] body parser! Support parsing text, buffer, json, json patch, json api, csp-report, multipart, form and urlencoded bodies. Works for koa@1, koa@2 and will work for koa@3.

Downloads

43

Readme

koa-better-body npmjs.com The MIT License npm downloads

Full-featured koa body parser! Support parsing text, buffer, json, json patch, json api, csp-report, multipart, form and urlencoded bodies. Works for koa@1, koa@2 and will work for koa@3.

code climate standard code style travis build status coverage status dependency status

You might also be interested in our recipes - working examples, answers, tips & tricks. Contribute a recipe?

Install

npm i koa-better-body --save

Features

Usage

For more use-cases see the tests

const koaBetterBody = require('koa-better-body')

koaBetterBody

Robust body parser for koa@1, also works for koa@2 (with deprecations). Will also work for future koa@3 with koa-convert.

Params

Example

var koa = require('koa')
var body = require('koa-better-body')
var app = koa()

app
  .use(body())
  .use(function * () {
    console.log(this.body)
  })
  .listen(8080, function () {
    console.log('koa server start listening on port 8080')
  })

Options

Sane defaults. :sparkles:

Accepts JSON, JSON API v1, text, buffer, csp-report, multipart and urlencoded/form bodies. If you want to disallow accepting and parsing multipart body you should pass multipart: false. Most of the defaults you can see at utils.defaultOptions and utils.defaultTypes. All options are also been passed to formidable.IncomingForm! Even you can pass IncomingForm instance to be able to handle the different formidable events.

  • fields {Boolean|String}: Default false, which means it will set fields on this.request.fields and directly on this.body. If you pass a string, for example 'foo', you will have fields on this.body and on this.request.foo.
  • files {Boolean|String}: Default false, which means it will set files on this.request.files and this.body.files, if you pass a string, for example 'bar', it will set files on this.request.bar and this.body.bar.
  • multipart {Boolean}: Default true. If you pass false it won't accept/parse multipart bodies.
  • textLimit {String}: Default '100kb'. Passed to bytes.parse method.
  • formLimit {String}: Default '100kb'. Passed to bytes.parse method.
  • jsonLimit {String}: Default '100kb'. Passed to bytes.parse method.
  • bufferLimit {String}: Default '1mb'. Passed to bytes.parse method.
  • jsonStrict {Boolean}: Default true. When set to true, JSON parser will only accept arrays and objects.
  • detectJSON {Function}: Custom JSON request detect function - detectJSON(ctx).
  • strict {Boolean}: Default true. Pass false if you want to allow parsing GET, DELETE and HEAD requests.
  • onerror {Function}: Custom error handle, if throw an error, you can customize the response - onerror(err, ctx).
  • extendTypes {Object}: Default accepting types can find on utils.defaultTypes function. Allowing you to extend what your app can accept. By default works for JSON, JSON API v1, multipart, text, urlencoded and csp-report.
  • IncomingForm {IncomingForm}: Pass an instance of formidable.IncomingForm to be able to handle formidable events.

A note about strict mode

We are trying to follow standards. :cat2:

You can pass strict:false, but see IETF HTTP/1.1 Message Semantics: Section 6.1 to understand why we stay to "strict mode" by default. GET, HEAD, and DELETE requests have no defined semantics for the request body, but this doesn't mean they may not be valid in certain use cases. Last two tests at test/options.js are showing usage on non-strict and strict mode.

Related

You might also be interested in these packages:

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

Contributing Recipes

Recipes are just different use cases, written in form of README in human language. Showing some "Pro Tips" and tricks, answering common questions and so on. They look like tests, but in more readable and understandable way for humans - mostly for beginners that not reads or understand enough the README or API and tests.

  • They are in form of folders in the root recipes/ folder: for example recipes/[short-meaningful-recipe-name]/.
  • In recipe folder should exist README.md file: see recipes/multipart/README.md.
  • The examples from the recipe README.md should also exist as separate .js files.
  • Examples in recipe folder also should be working and actual.

It would be great if you follow these steps when you want to fix, update or create a recipes. :sunglasses:

  • Title for recipe idea should start with [recipe]: for example[recipe] my awesome recipe
  • Title for new recipe (PR) should also start with [recipe].
  • Titles of Pull Requests or Issues for fixing/updating some existing recipes should start with [recipe-fix].

It will help a lot, thanks in advance! :yum:

Charlike Make Reagent new message to charlike freenode #charlike

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github