Coder Social home page Coder Social logo

body's People

Contributors

donatj avatar jwolski avatar jwolski2 avatar raynos avatar tellnes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

body's Issues

Consider weakmap caching.

If body were to contain a weakmap cache of HttpRequest => raw body it means you would be able to use body(req, res, cb) anywhere irregardless of whether it has already been parsed.

This would be useful in an application where you don't want to do req.body = body or context.body = body but still want to read the body.

Is this a good idea?

cc @jonathanong

anyBody throws an error for text/plain content types

So anyBody only really accepts json or form encoded bodies, which makes the name of the function a bit confusing.
I would expect it to fall back to the default textBody implementation, especially for content types of text/*

Update Error pacakge

@Raynos currently body is using "error": "~2.0.4", which has now 7.x package, will be good to update the dependency.

refactor so we can use this module in both connect and co (koa)

was thinking about this during dinner. would be nice if we refactored this so it could be more of a body parsing utility vs "middleware". then connect could depend on this. also, i don't like how koa-body-parser modifies the context, so making this a yieldable would eliminate the need for koa-body-parser

some thoughts:

  • it should have a body(req, options, callback), body.json(req, options, callback), and body.urlencoded(req, options, callback) signatures. not sure what options to pass other than those to raw-body.
  • it should set default options on a new instance via body = require('body')(options) meh
  • it should return a thunk so you can do var obj = yield body(this.req, options) in koa, but could be used in any generator-based control flow.
  • for middleware, we can check if the second argument is a http.ServerResponse instance so we don't have to do something like app.use(body.json.middleware(options)) though I'm not sure how to set options.

some other things required for connect backwards compatibility:

  • should optionally allow qs as the url encoded parser
  • should do strict and non-strict JSON parsing

koa

any chance of supporting .req or maybe we could formalize something akin to .toJSON() for libs that encapsulate node's objects

var body = yield jsonBody(req, res)
var body = yield jsonBody(this)

api-wise maybe instead of "reaching" into module:

var parse = require('body');
var body = yield parse.json(this);

and for any just:

var parse = require('body');
var body = yield parse(this);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.